Load a list subset with pickle?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Oct 16 02:48:20 EDT 2009


En Thu, 15 Oct 2009 16:28:11 -0300, Peng Yu <pengyu.ut at gmail.com> escribió:
> On Thu, Oct 15, 2009 at 12:01 PM, Gabriel Genellina
> <gagsl-py2 at yahoo.com.ar> wrote:
>> 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.

>>> try:
>>>  while 1:
>>>    e = pickle.load(input)
>>>    print e
>>> except EOFError:
>>>  pass
>>
>> Pickle the list length before its contents.
>
> Suppose that the list length was not in
> 'serialize_list.output/serialize_list.pkl'. Is try-except block the
> best solution?

I don't know if it's the best, but it's the one I'd probably use.

-- 
Gabriel Genellina




More information about the Python-list mailing list