know reference name in instance

pipehappy pipehappy at gmail.com
Fri Jul 7 07:49:08 EDT 2006


Fredrik Lundh wrote:

> 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
>
I may choose the name when the class is initialized, other may choose
the newest name. It depends.
> or
>
>     x = [test(), test(), test()]
>
> ?
None may be the good answer here.
>
> for more on this, see:
>
> http://pyfaq.infogami.com/how-can-my-code-discover-the-name-of-an-object
>
> </F>
Yes, You are right. But variety of condition is not necessary
prohibiting the promotion of such question but provides the possibility
for different answer. So is there some way I can ask the environment to
tell me the name? 

With respect, I read your words and it's great.




More information about the Python-list mailing list