29.1.2010 3:25, bradknox kirjoitti:
> Alex Grönholm-3 wrote:
>> 28.1.2010 10:51, bradknox kirjoitti:
>>> Hi guys. I can't make heads or tails of this.
>>> Class file WekaBatchInterfaceJ.java is contained in
>>> which is at the bottom of a hierarchy of Python objects. I'd like to
>>> serialize the top-level Python object, but there is a problem with
>>> When I try to use pickle.dump(), I get:
>>> TypeError: can't pickle WekaBatchInterfaceJ objects
>>> And when I use Java io (as described in Part 9 at
>>> can save the object instance without errors. But when I try to
>>> the object instance, I receive the following error:
>>> Traceback (most recent call last):
>>> File "PickleAgent.py", line 127, in<module>
>>> File "PickleAgent.py", line 75, in __init__
>>> self.mca = loadObject(agentFileName)
>>> File "PickleAgent.py", line 37, in loadObject
>>> readInstance = inStream.readObject( )
>>> AttributeError: 'module' object has no attribute 'WekaBatchInterfaceJ'
>>> So you know, WekaBatchInterfaceJ does implement Serializable and all of
>>> class variables either implement Serializable or are marked transient.
>>> Is it just not possible to accomplish this, or am I doing something
>>> incorrectly? I'm trying to run some human subject experiments tomorrow,
>>> any advice would be incredibly appreciated.
>>> - Brad Knox
>> Use Pickle protocol 2:
>> pickle.dump(obj, file, 2)
>> The default protocol (level 0) is worthless.
>> The Planet: dedicated and managed hosting, cloud storage, colocation
>> Stay online with enterprise data centers and the best network in the
>> Choose flexible plans and management services without long-term contracts
>> Personal 24x7 support from experience hosting pros just a phone call away.
>> Jython-users mailing list
> Thanks, Alex, for the quick suggestion. Unfortunately, it also resulted in
> an error (different than with the default protocol). I'd reproduce the error
> for you, but I ended up saving the important information to file manually (a
> bunch of arrays turned to strings), and I'd be tempting fate to mess with
> the now-working code.
This probably has to do with the particular classes you are trying to
pickle, because I've successfully tested pickle for dumping Java objects.
> - Brad