How to obtain the reference name

Gerhard Häring gerhard.haering at opus-gmbh.net
Mon Mar 10 08:04:35 EST 2003


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