weird pickle behavior in Python 3.1.2 + Eclipse 3.5.2
kirby.urner at gmail.com
kirby.urner at gmail.com
Fri Jun 4 11:27:17 EDT 2010
Here we are in an Eclipse pydev console, running Python 3.1.2. For
the most part, everything is working great.
However...
>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
C:\Python31\python.exe 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC
v.1500 32 bit (Intel)]
>>> import pickle
>>> class Example:
... def __init__(self):
... self.name = "Hello"
... def __repr__(self):
... return "an Example object named {}".format(self.name)
...
...
>>> obj = Example()
>>> obj
an Example object named Hello
Note that I'm opening in binary, like I'm supposed to with this
latest protocol:
>>> f = open("testpickle.pkl",'wb')
Should be able to do this, no problemo:
>>> pickle.dump(obj, f)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python31\lib\pickle.py", line 1354, in dump
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'Example'>: attribute
lookup builtins.Example failed
The above works fine in "naked Python" 3.1.2 by the way.
So this could be a problem with Eclipse / Pydev and/or
user error. What am I missing?
Just normal data structures work:
>>> test = [1,2,3]
>>> pickle.dump(test,f)
>>> f.close()
>>>
Any other Eclipse users out there who can at least duplicate this
weirdness?
Kirby Urner
in Portland "Keep Portland Weird" Oregon
More information about the Python-list
mailing list