From: Alex G. <ale...@ne...> - 2010-01-29 02:09:28
|
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 >>> WekaBatchInterfacePy.py, >>> 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 >>> WekaBatchInterfaceJ. >>> >>> >>> 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 >>> http://www.oreillynet.com/pub/a/python/2002/04/11/jythontips.html?page=2), >>> I >>> can save the object instance without errors. But when I try to >>> unserialize >>> the object instance, I receive the following error: >>> >>> Traceback (most recent call last): >>> File "PickleAgent.py", line 127, in<module> >>> AgentLoader.loadAgent(PickleAgent()) >>> 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 >>> its >>> 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, >>> so >>> 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 >> business >> Choose flexible plans and management services without long-term contracts >> Personal 24x7 support from experience hosting pros just a phone call away. >> http://p.sf.net/sfu/theplanet-com >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users >> >> >> > 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 > |