Stringify object reference?
pyth at devel.trillke.net
Fri Oct 11 20:23:16 CEST 2002
Alan Kennedy wrote:
> Alan Kennedy wrote:
> >> Basically, I'm looking for the python equivalent of a CORBA IOR.
> >> Any suggestions? Or am I missing something completely obvious?
> holger krekel wrote:
> > Python's id of an object 'id(obj)' won't help you at all. There
> > is no mechanism for reinstantiating an object by its serialized
> > id. You probably should look for CORBA-Orbs such as Fnorb or
> > OmniORB. Or maybe the Zope Object DataBase (ZODB) would fit
> > your needs.
> > A bit more context might help us to help you <wink>.
> As I mentioned in my original post, I want to annotate (generic) XML
> tree-like object models (e.g. DOM, etc) with my own python objects.
the 'id' of an object is only useful within the lifetime of the process.
I presume that you want to be able to restart your process so forget
about 'id' completly.
I don't know if others have a solution for your specific problem
(annotating DOM-trees with python objects). IMO it's not exactly
If you are willing to spend an ID-attribute on each element it
gets easier. You could register an annotation object using
this ID as a reference. You have to generate these IDs yourself.
There are plenty of algorithms for generating UUIDs (universally
unique ids) on the web.
Now setup a dictionary mapping the IDs to your python objects
and pickle this dictionary into a separate file, parallel
to your xml-file. When you load the XML-file you also unpickle
that dictionary and have fast access to annotations.
Write a method that registers an annotation with a node
and a lookup-method for finding it.
More information about the Python-list