know reference name in instance

Fredrik Lundh fredrik at pythonware.com
Fri Jul 7 05:05:06 EDT 2006


pipehappy wrote:

> Is it possible for an instance know its name used by other part of
> program.  I mean like this:
> 
> class test:
>     def __init__(self):
>         pass
> 
> when some one writes
> 
> x = test()
> 
> then one of attribute of x contain the name "x"
> 
> Is it possible?

not really.

and what should happen if you do, say

    x = test()
    y = x

or

    x = [test(), test(), test()]

?

for more on this, see:

http://pyfaq.infogami.com/how-can-my-code-discover-the-name-of-an-object

</F>




More information about the Python-list mailing list