python - What is the best way to write data to disk to read from it? -


yesterday did many experiments data writing file , read them it. experienced many difficulties simple task. @ first thought, can save data file is. example - save list file.txt , read variable list. found solution on stackoverflow , think simplest way read list file.txt

with open('file.txt', 'r') f:     list_variable = ast.literal_eval(f.read()) 

so, newbie in programming, know more experienced coders - best way save data disk future import?

i using stings, dictionaries, lists , tuples. there accurate , simple way work with? (txt, csv, json ... etc.)?

the basic idea of writing / reading / files need serialize data (see wikipedia).

in order retrieve data , restore data structure of choice (i.e. tuples, lists or w/e) need way *de-*serialize data read. can achieved parsing input stream of data.

as solution matter, can use json package importing , use json.dumps(...) , json.loads(...) respectively write , read json formatted data.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -