From: Peter Otten <[email protected]> wrote:
snip
<<How did you write the data into the pickle file? The normal approach is to
write all your data in one step, e. g. (all code snippets untested)>>
Thanks Peter, that was it. I was treating pickle like standard file
i/o when it's not that at all.
The reason why I'm "pickling" is I'm trying to include information on
Python data structures in the presentaton I'm preparing.
Here are the two programs that now work correctly together:
import pickle
pickle_file = open("d:/Work/pickle_file", "wb")
Qb_dict = {"Montana": ["Joe", "Montana", "415-123-4567",
"[email protected]","Candlestick Park"],
"Tarkington": ["Fran", "651-321-7657", "[email protected]",
"Metropolitan Stadidum"],
"Namath": ["Joe", "212-222-7777", "[email protected]", "Shea Stadium"],
"Elway": ["John", "303-9876-333", "[email protected]", "Mile High Stadium"],
"Elway": ["Ed", "303-9876-333", "[email protected]", "Mile High
Stadium"],
"Manning": ["Archie","504-888-1234", "[email protected]",
"Louisiana Superdome"],
"Staubach": ["Roger","214-765-8989", "[email protected]",
"Cowboy Stadium"]}
pickle.dump(Qb_dict, pickle_file)
pickle_file.close()
#
# pickle_in.py
# program to read in a pickled file
#
# Frank L. Palmeri
#
import pickle # import the pickle
module
pickle_file = open("d:/Work/pickle_file", "rb") # open the pickled file
read_list = pickle.load(pickle_file) # read the first pickled row
print(read_list) # print the input row from
the pickled file
pickle_file.close() # close the pickled file
--
Frank L. "Cranky Frankie" Palmeri
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor