How to obtain the reference name

Paco barreraf at inicia.es
Tue Mar 11 02:33:18 EST 2003


That's no the question. The problem is I would make reference to instance of
the class, from an attribute of the class.
This is because I need an attribute that contain python code, and this code
need make reference to the instance name.
That's is:

class A:
     def __init__(self):
        self.instance_Name = 'the name I would of the instance'
        self.code = "print 'The name of the instance is:' +
self.instance_Name"




"Gerhard Häring" <gerhard.haering at opus-gmbh.net> escribió en el mensaje
news:slrnb6p39d.280.gerhard.haering at haering.opus-gmbh.net...
> Paco <barreraf at inicia.es> wrote:
> > Hy, somebody know how to obtain the name of an instance out of any
methods
> > of the claas.
> > Example:
> >
> > class A:
> >     def __init__(self):
> >         print 'hello'
> >
> > j=A()
> >
> > I need to obtain the name of the instance "j", something as is:
> > "j.name" and the value returned was "j"
>
> That's not possible. One object needn't be referred to by only one
> name. It can be referred to by many names. For example if you continue
> the above code with:
>
> j2 = j
> j3 = j
> j4 = j2
> j = None
>
> -- Gerhard






More information about the Python-list mailing list