471,331 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,331 software developers and data experts.

Bug in cPickle with packages and 'object' inherited class

Say you have this structure:

pna/
__init__.py
model.py
__init__.py is empty.

model.py is:
import cPickle as pickle

class A(object):
pass

def serialize():
pickle.dump(A(), open('temp.dat', 'wb'))
Now open a python interpreter on the root directory of that structure
and type:
import pna.model
pna.model.serialize()
The following exception is thrown:
Traceback (most recent call last):
File "test.py", line 2, in <module>
pna.model.serialize()
File "...\pna\model.py", line 7, in serialize
pickle.dump(A(), open('temp.dat', 'wb'))
cPickle.PicklingError: Can't pickle <class 'pna.model.A'>: import of
module pna.model failed
If you use 'pickle' instead of 'cPickle', it works.
If you don't inherit from 'object' in 'A', it works.

I'm using Python 2.5.1 on Windows XP. I've tested in Python 2.4.4 on
Linux and it works.

Any ideas of what is going on?

Thanks,
Conrado

Jul 25 '07 #1
1 1215
En Wed, 25 Jul 2007 17:32:46 -0300, Conrado PLG <co********@gmail.com>
escribió:
Say you have this structure:

pna/
__init__.py
model.py
__init__.py is empty.

model.py is:
import cPickle as pickle

class A(object):
pass

def serialize():
pickle.dump(A(), open('temp.dat', 'wb'))
Now open a python interpreter on the root directory of that structure
and type:
import pna.model
pna.model.serialize()
The following exception is thrown:
Traceback (most recent call last):
File "test.py", line 2, in <module>
pna.model.serialize()
File "...\pna\model.py", line 7, in serialize
pickle.dump(A(), open('temp.dat', 'wb'))
cPickle.PicklingError: Can't pickle <class 'pna.model.A'>: import of
module pna.model failed
It works for me. What are those "..." in the file name?

--
Gabriel Genellina

Jul 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Guenter Walser | last post: by
reply views Thread by Simon Dahlbacka | last post: by
2 posts views Thread by sh | last post: by
1 post views Thread by A.B., Khalid | last post: by
2 posts views Thread by les | last post: by
8 posts views Thread by Jeff Poole | last post: by
8 posts views Thread by Victor Kryukov | last post: by
reply views Thread by =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post: by
1 post views Thread by Barry | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.