The situation is this. There are about one hundred records of this type:

{'name': 'Yuri', 'start': 55, 'enemies': ('Nick', 'Lora', 'Frank', 'Bernard', 'Phoebee', 'Jack', 'Cristina', 'Stephen', 'Joe', 'Gary', 'Robert')} 

This is one entry. Previously, the shelve module was used to store them. Now I need something cross-platform, and I do not know what to choose. Data in the future will not be changed by the program or somehow supplemented, they will remain exactly the same.

All that will happen "inside" is receiving information from these dictionaries: for example, by the name of Yuri it will be necessary to find start and its enemies and, if there is Lora among them, then to find its enemies , well, like that. There was an option to use csv , but I'm not sure if this is a good choice in this case. What are the suggestions? Justify your answer, please.

  • 2
    For one hundred records, anything at all is suitable - andreymal
  • @andreymal Even if you make, say, a dictionary of dictionaries or a list of dictionaries? Speed ​​is important, but it is not particularly critical. - Newbie
  • For one hundred records, anything will be fast. Now, if there were hundreds of millions of records, then it would become a problem :) Well, in any case, you can independently measure the performance of all available methods and select the fastest - andreymal

1 answer 1

For this amount of data and given the fact that they do not change and should be available cross platform, you should look in the direction of JSON.

It is easy to store objects like dictionaries and tools for working with JSON in the standard library of almost every PL.

  • If I use json save the dictionary of dictionaries to the data.json file, then when retrieving the data from the record, it is better to open one of the dictionaries, thereby opening the file every time ( json.load(file)['ключ'] ), or load first whole dictionary of dictionaries in a variable, and then get data from a variable ( data = json.load(file); data['ключ'] )? Will opening a file have a bad effect ten times in a second? - Newbie
  • @Newbie second option, it makes no sense to jerk the file constantly - this is a relatively slow operation - dizballanze