C
Conrado PLG
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
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