Reputation: 3771
I have a list with a lot of things in.
At the end of my script I would like to store it in a file.
And when I start another script another day, I would like to extract my list from my file and then use it.
I don't know if it's the best way to do this.
Here is what i would like to do in "code" for those who didn't understand
#script1
l = ('hey', 'ho', 'hello', 'world')
#save list into myfile
#script2
l = getmylistfrommyfile()
print(l)
>>>('hey', 'ho', 'hello', 'world')
#I can now use my list !
Upvotes: 0
Views: 119
Reputation: 22954
If you are looking for the best and most pythonic way of doing this then Pickling is a better idea. It is as simple as :
#Save a dictionary into a pickle file.
import pickle
favorite_color = { "lion": "yellow", "kitty": "red" }
pickle.dump( favorite_color, open( "save.p", "wb" ) )
# Load the dictionary back from the pickle file.
favorite_color = pickle.load( open( "save.p", "rb" ) )
Upvotes: 3