By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,498 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

Help with cPickle for deserializing datetime.datetime instances

P: n/a
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
Oct 14 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mingus Tsai wrote:
When*these*three*statements*run,*the*IDLE*crashes!


Is there a traceback that you can provide (cut and paste)?

Peter
Oct 14 '05 #2

P: n/a
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
Oct 14 '05 #3

P: n/a
Hans Georg Krauthaeuser wrote:
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


here's the code from my pickling:
#dict of arrays of datetime objects
export1 = {'gagetime':gagednt2ar,'gagetime_offset':gagednt2_ offsetar,
'tektime_lagb':mdntmar,'tektime':mdntzar,'tektime_ lagf':mdntpar}

#dict of arrays of built-in objects
datamat = {'az':azrowfar,'el':elrowfar,'tekrange_lagb':mtmt,
'tekrange':mtzt,'tekrange_lagf':mtpt,'teksig_lagb' :mvmt,
'teksig':mvzt,'teksig_lagf':mvpt,'gagerange':gager ange,
'gagesig':gagesig}

time_out = open('tsm2_outa','w')
cPickle.dump(export1,time_out)
time_out.close()

data_out = open('tsm2_outb','wb')
cPickle.dump(datamat,data_out,1)
data_out.close()

------ So, you can see that the first dict is pickled in ascii (those
arrays are pretty small), but the second dict (the one that i have no
problem unpickling) is pickled in binary. However, I have tried both
ascii and binary for the frist dict, but both crash the IDLE. I don't
understand how pickling works with non built-in objects--is it necessary
for me to tell it that I have datetime objects and how do i do that?

Or perhaps there's something entirely different happening?

much obliged, Ming
Oct 14 '05 #4

P: n/a
Peter Otten wrote:
Mingus Tsai wrote:

When these three statements run, the IDLE crashes!

Is there a traceback that you can provide (cut and paste)?

Peter


It is a hard crash, so there is no traceback. Instead, a dialog window
pops up and gives the standard windows xp response to a program that has
crashed. I then click restart in the box and the IDLE does a restart
and is back to normal, but no traceback...

cheers,
Ming
Oct 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.