How do you make sure the dictionary doesn't drop when the code's off?
-
Let's say I have a dictionary.
Key and meaning, I'm asking the user. But after the code's out, if I want the dictionary out, it's empty.Can we do something to keep the dictionary from dropping?
-
There is an integrated module in in Python to show/develop facilities. https://docs.python.org/3/library/pickle.html ♪
This module can be stored in the file and downloaded from the file any Python objects (transferable, class objects, etc.):
import pickle
data = {"keys": "value"}
сериализация
with open('data.pickle', 'wb') as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)Example of reading data from Pickle file:
# десериализация
with open('data.pickle', 'rb') as f:
data = pickle.load(f)