Get name of class without instance
bryanvick at gmail.com
Wed Jun 24 12:28:56 EDT 2009
On Jun 24, 9:25 am, Tim Golden <m... at timgolden.me.uk> wrote:
> 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"
> You are going to kick yourself:
> class Foo (object): pass
> print Foo.__name__
How come dir(Foo) does not show __name__? That is how I was
investigating the possibilities.
More information about the Python-list