Re: [Py4j-users] Using copy.deepcopy() with Java Objects
Status: Beta
Brought to you by:
barthe
From: Nicolò P. <nic...@us...> - 2011-03-16 11:48:28
|
Hi, actually what I am trying to do is a software transactional memory library in Python able to add transactional support to Java programs. To simplify let's say that I would like to call a commit() operation in the Java program (for example a commit for each object) that call a Python routine that get the object from Python and store it safely, meaning that changes to the object in the Java-side don't reflect the effects in the object stored in the Python-side. Then I could call a restore() operation in the Java object, that take last saved object in the Python-side and replace the current instance of the Java object. I know it is a bit writhed or maybe useless, but it is just an experiment. bye Nicolò Perino ______ PhD Student @ USI - Faculty of Informatics http://www.people.usi.ch/perinon/ On 16 Mar 2011, at 12:04, Barthelemy Dagenais wrote: > Hi Nicolò, > > as Alex says, it is not possible to use deepcopy with a Java object in > Python and I'm not sure it makes sense anyway. Are you trying to > dynamically duplicate a Java object graph from Python or...? > > With more information about what you are trying to do, we may be able to > find an alternative. > > Barthélémy > > On 03/16/2011 06:50 AM, Alex Grönholm wrote: >> 16.03.2011 12:24, Nicolò Perino kirjoitti: >>> Hi, >>> I was experimenting with your library P4JS and I was wandering how to create a copy of a Java object in Python environment. So I tried with the Python copy module, starting from your "stack" example: >>> >>>>>> stack = gateway.entry_point.getStack() >>>>>> stack >>> JavaObject id=o0 >>>>>> import copy >>>>>> a = copy.deepcopy(stack) >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in<module> >>> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy.py", line 173, in deepcopy >>> y = copier(memo) >>> File "/Library/Python/2.6/site-packages/py4j/java_gateway.py", line 343, in __call__ >>> args_command = ''.join([get_command_part(arg, self.pool) for arg in new_args]) >>> File "/Library/Python/2.6/site-packages/py4j/protocol.py", line 208, in get_command_part >>> command_part = REFERENCE_TYPE + parameter._get_object_id() >>> AttributeError: 'dict' object has no attribute '_get_object_id' >>> >>> Is there a way to success in coping objects? >> You'll have to do it on the Java side. The exact method depends on what >> type you are trying to copy. >>> Thank you. >>> Bye >>> >>> >>> Nicolò Perino >>> ______ >>> PhD Student @ USI - Faculty of Informatics >>> http://www.people.usi.ch/perinon/ >>> >>> >>> ------------------------------------------------------------------------------ >>> Colocation vs. Managed Hosting >>> A question and answer guide to determining the best fit >>> for your organization - today and in the future. >>> http://p.sf.net/sfu/internap-sfd2d >>> _______________________________________________ >>> Py4j-users mailing list >>> Py4...@li... >>> https://lists.sourceforge.net/lists/listinfo/py4j-users >> >> >> ------------------------------------------------------------------------------ >> Colocation vs. Managed Hosting >> A question and answer guide to determining the best fit >> for your organization - today and in the future. >> http://p.sf.net/sfu/internap-sfd2d >> _______________________________________________ >> Py4j-users mailing list >> Py4...@li... >> https://lists.sourceforge.net/lists/listinfo/py4j-users > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users |