A
A
Anton2018-08-17 14:07:03
Python
Anton, 2018-08-17 14:07:03

How to save lists to a file and get them from a file?

Please tell me how to save a list like this to a file:

[('config.h', '.\\mb_config.h', '83A7A716'), ('mainCpp.cpp', '.\\mainCpp.cpp', '30FCD925')]

And the next time you start the program, restore this list for further interaction with it ...
Or am I not moving in the right direction at all and it’s not customary to store the parameters this way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
igorzakhar, 2018-08-17
@8toni8

>>> data = [('config.h', '.\\mb_config.h', '83A7A716'), ('mainCpp.cpp', '.\\mainCpp.cpp', '30FCD925')]
>>> import pickle
>>> with open('data.pickle', 'wb') as fp:
...     pickle.dump(data, fp)
... 
>>> with open('data.pickle', 'rb') as fp:
...     data_new = pickle.load(fp)
... 
>>> data_new
[('config.h', '.\\mb_config.h', '83A7A716'), ('mainCpp.cpp', '.\\mainCpp.cpp', '30FCD925')]

A
Alexander Proshchenkov, 2018-08-17
@Keltor

Maybe csv files will help you
https://docs.python.org/3/library/csv.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question