can I query an instance for its name?

Luc Lefebvre luc at B57-90.python.org
Sat Sep 30 11:27:57 EDT 2000


Hi Bjorn,

I would like to see:

>>> x.who()
>>> x is an instance of class foo

--
Luc Lefebvre

Open Source, a strategic choice
for mission-critical applications

Key fingerprint = D2E5 5E35 B910 6F4E 0242  EC63 0FD9 96D0 C7F4 784E
On Fri, 29 Sep 2000, Bjorn Pettersen wrote:

> so if I do:
> 
>  x = foo()
>  y = x
>  y.who()
> 
> what should it print?
> 
> -- bjorn
> 
> Luc Lefebvre wrote:
> > 
> > Hi,
> > 
> > <\newbie alert on>
> > 
> > I have been attempting to get access to instance names, eg:
> > 
> > class foo:
> >         def __init__(self):
> >                 pass
> > 
> >         def who(self):
> >                 print "%s is an instance of class %s" % (self.????, self.__class__)
> > 
> > if __name__=="__main__":
> >         x=foo()
> >         x.who() # would expect "x is an instance of class foo"
> > 
> > Also, is there a way to enquire as to a given classes children eg: foo.__children__?
> > 
> > <\newbie alert off>
> > tia
> > 
> > --
> > http://www.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list