pickle.load() all dict

Yutao Deng edquiver at gmail.com
Sat May 15 13:29:41 EDT 2010


Hi all:
I'm trying to learn to use Python  wrote a applet to record every day doing.
and i use the pickle
pickle.dump something to file no problem i think.
but pickle.load whith a problem. can not load all dict do my way that what i
pickle.dump().

My code:
####
import cPickle as pickle
pickle_file = open("data2","rb")
i = pickle.load(pickle_file)
print i
i = pickle.load(pickle_file)
print i
i = pickle.load(pickle_file)
print i
i = pickle.load(pickle_file)
print i
i = pickle.load(pickle_file)
print i
####
console show :
{'2010-5-23': ['1242', 'first']}
{'2010-5-24': ['1232', 'third']}
{'2010-5-25': ['211', 'second']}
{'2010-3-22': ['3211', 'fourrrr']}
{'2050-3-2': ['3990', '322']}

This is i want but that's silly. if the dict too much, then i have not
ideas.

the other way from
http://mail.python.org/pipermail/tutor/2005-July/039859.html

####
import cPickle as pickle
pickle_file = open("data2","rb")

number_of_pickles = pickle.load(pickle_file)
for n in range(number_of_pickles):
    p = pickle.load(pickle_file)
    print p
####
this way didnt work for me.

console show:
Traceback (most recent call last):
    number_of_pickles = pickle.load(pickle_file)
cPickle.UnpicklingError: invalid load key, '
'.
how do i define the range of pickle.load a file. i mean that how can i know
how many dict in the data2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100516/ae24bb2f/attachment.html>


More information about the Python-list mailing list