Finding the name of a class

John Salerno johnjsal at NOSPAMgmail.com
Tue Aug 1 11:56:18 EDT 2006


Tim Chase wrote:

> While this is surely true, would somebody explain why I had such trouble 
> finding this?

I think __name__ is an attribute of the class itself, not the instance:

 >>> class Foo(object):
	pass

 >>> f = Foo()
 >>> f.__name__

Traceback (most recent call last):
   File "<pyshell#4>", line 1, in -toplevel-
     f.__name__
AttributeError: 'Foo' object has no attribute '__name__'
 >>> Foo.__name__
'Foo'



More information about the Python-list mailing list