I have a Python script that returns a dict which I want to store somewhere to be used in a bigger project (the script is slow to run so I don't want to just import the script each time I want the dictionary).
The dict is small so I see two options. I can:
- Save the dict to a pickle file
Write the dict as a literal to a new .py file, like so:
my_dict = slow_func() with open('stored_dict.py', 'w') as py_file: file_contents = 'stored_dict = ' + str(my_dict) py_file.write(my_dict)
Then I can access the dict literal using
from stored_dict import stored_dict
Should I prefer one of these options?