Load a list subset with pickle?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Oct 15 13:01:28 EDT 2009
En Thu, 15 Oct 2009 13:05:18 -0300, Peng Yu <pengyu.ut at gmail.com> escribió:
> How do I determine if I have loaded all the elements? I use the
> following code. I'm wondering if there is any better solution than
> this.
>
>
> ###############
> import pickle
>
> alist = [1, 2.0, 3, 4+6j]
>
> output=open('serialize_list.output/serialize_list.pkl', 'wb')
> for e in alist:
> pickle.dump(e, output)
> output.close()
>
> input=open('serialize_list.output/serialize_list.pkl', 'rb')
>
> try:
> while 1:
> e = pickle.load(input)
> print e
> except EOFError:
> pass
Pickle the list length before its contents.
--
Gabriel Genellina
More information about the Python-list
mailing list