Thanks, Tony, your example is much clearer (to me!) than that on the python page. A couple quick questions about it:
So the .dump command is, in effect, saving the file, correct? which takes the object you're saving (in my case it would be high_scorelist), and ("filename","..... what is the "w" ?) Why does the temp file you're saving into end in .pik?
Then import is, in effect, loading the file (the score list) from wherever you saved it. do you have to give it a new name? (i.e., "my_list_reloaded"?) I'm thinking not. i could import the file right before the high score list is displayed in the game, and dump right after a new score is added/the list is changed?
Thanks for creating an easy-to-follow example!
:)
~Denise
Okay,
pickle writes ("w") text to a file. The tempfile he's saving it as ends in pik because he wants it to.
I assume you're using Windows? Go to control panel, folder options, view, and make sure the "Hide extensions for known file types" is unchecked.
Then go to a folder that has any file in it. You'll see file extensions on the names. i.e. myfile.txt
Extensions are just something the operating system, in this case Windows, uses to know what program to use to open the file. Since you are controlling the file temp.pik or whatever it's called, it doesn't matter what the operating system knows about it. You could even give it four letters, or two, or even one letter, or believe it or not, not any extension at all.
It does not matter when you use the exact same filename reloading.
As for the variable name, it doesn't usually matter what the variable name was before! Any python tutorial will show you at least that reassigning a variable will make the variable point to the new value and the old value will be lost. In this case, the old variable is not lost, because you can still reload it from the file.
Okay, I'm done,
Jacob
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor