Help with cPickle for deserializing datetime.datetime instances

Hans Georg Krauthaeuser hgk at et.uni-magdeburg.de
Fri Oct 14 05:08:45 EDT 2005


Mingus Tsai schrieb:
> Hello- please help with unpickling problem:
> 
> I am using Python version 2.3.4 with IDLE version 1.0.3 on a Windows
> XPhome system.
> 
> My problem is with using cPickle to deserialize my pickled arrays of
> datetime.datetime instances.  The following is the code I have written:
> 
>     import cPickle, datetime
>     import Numeric
> 
> #the file below contains a serialized dict with arrays of datetime
> #objects.  When these three statements run, the IDLE crashes!
> 
>     input1 = open('tsm2_outa','r')
>     time1 = cPickle.load(input1)
>     input1.close()
> 
> #the file below contains serialized dict with arrays of built-in objects
> #it unpickles without any problem, when I omit the above unpickling
> #operation.
> 
>     input2 = open('tsm2_outb','rb')
>     data1 = cPickle.load(input2)
>     input2.close()
> 
> My guess is that I need to somehow tell the pickle.load command that it
> is loading datetime instances, but I have no idea how to do this.  Any
> help would be much appreciated.
> 
> Thanks,
> Ming
How did you wrote the pickle-file. If you used mode 2 you have to open
the file with mode "rb", as you did for the other pickle file.

Hans



More information about the Python-list mailing list