Object identifier in constructor

Marc LAZAREFF lazareff at onera.fr
Wed Dec 8 05:17:43 EST 1999


I have the following problem :

In the Python interface of a C++ CFD code (the elsA software, developed
here at ONERA), cross-references between user defined objects are made
through string identifiers, which
should be the same as the Python object identifiers, ex:

Creating the 'm1' instance of the 'model' class like this :

  m1=model()

should (for the current scheme to work celanly) allow for the 'm1`
string identifier for object m1 to be recovered (in the `model' class
constructor) and properly conveyed to the C++ kernel to be stored as an
attribute of the bound C++ object (we use SWIG with shadow mode).

Such a string identifier allows user defined references to 'm1' from
other Python objects, ex:

  b1=block()
  b1.attach('m1')

We can't use a hash or equivalent on the m1 object to use as an
identifier, because the reference to it may be made before it is created
(this allows cross-references between two objects without the
chicken-egg problem). A `link-like' post processing is not appropriate,
because the interface may be used interactively.

The present solution involves scanning __main__.__dict__ (the scope in
which all user objects are registered by the interface) as soon as
possible after the object creation, to lookup the object's address in
__main__.__dict__.values() and thus get at the corresponding key (the
object's name).

This sounds silly, and I guess it is. Also, using the code on a large
number of user objects leads to a time penalty which is not fully
acceptable.


So, apart from the possibility of other possible cross-referencing
schemes, is there a solution to :

            "Get the object's Python identifier (as in dir()) while
still in the constructor"

???  8-P

Hopefully (and anyway) with many thanks,

Marc

--
Marc Lazareff                       | Phone (direct) 1 46 73 42 73
ONERA 29,Ave de la Division Leclerc |
92320 CHATILLON FRANCE              | E-Mail         lazareff at onera.fr







More information about the Python-list mailing list