Getting a class name
Fuzzyman
fuzzyman at gmail.com
Sun Feb 18 07:24:47 EST 2007
On Feb 17, 8:33 pm, deelan <g... at zzz.it> wrote:
> Harlin Seritt wrote:
> > Hi,
>
> > How does one get the name of a class from within the class code? I
> > tried something like this as a guess:
>
> > self.__name__
>
> Get the class first, then inspect its name:
>
> >>> class Foo(object): pass
> ...
> >>> f = Foo()
> >>> f.__class__.__name__
> 'Foo'
> >>>
>
Why is the __name__ attribute not available to the instance? Why don't
normal lookup rules apply (meaning that a magic attribute will be
looked up on the class for instances) ?
Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml
> HTH
>
> --
> d.
More information about the Python-list
mailing list