name of 'name'

Asun Friere afriere at yahoo.co.uk
Tue Mar 23 23:08:25 EST 2004


"Larry Bates" <lbates at swamisoft.com> wrote in message news:<ouOdneoz7fGL-8LdRVn_iw at comcast.com>...
> Not exactly sure I understand the question, but here
> goes:
> 
> If you are talking about a class, you can get the
> classname from :
> 
> self.__class__.__name__
> 
> Hope info helps.
> 
> -Larry
> 

Nope, that would give the name of the class of the instance, whereas
her code retrieves the name of the instance itself.  Eg.

>>> name = lambda x: [y for y in globals().keys() if
globals()[y]==x][0]
>>> foo = 5
>>> bar = 'hello'
>>> baz = [foo, bar]
>>> baz[0].__class__.__name__
'int'
>>> name(baz[0])
'foo'
>>>



More information about the Python-list mailing list