Get name of class without instance

J. Cliff Dyer jcd at sdf.lonestar.org
Wed Jun 24 12:36:19 EDT 2009


On Wed, 2009-06-24 at 09:17 -0700, Bryan wrote:
> Given a class:
> 
> class Foo(object):
>     pass
> 
> How can I get the name "Foo" without having an instance of the class?
> 
> str(Foo) gives me more than just the name Foo.   "__main__.Account"
> Foo.__class__.__name__ gives me "type"
> 
> I don't want to do:
> Foo().__class__.__name__ if possible.  I would rather avoid the
> constructor.  I just want to get a string "Foo"
> 

I'll give you a hint:

>>> Foo().__class__ is Foo
True





More information about the Python-list mailing list