Getting a class name

goodwolf Robert.Katic at gmail.com
Sun Feb 18 12:14:41 EST 2007


On Feb 18, 9:17 am, "Gabriel Genellina" <gagsl... at yahoo.com.ar> wrote:
> En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <Robert.Ka... at gmail.com>
> escribió:
>
> > I suppose that you wont get class name into its code (or before
> > definition end) but not into a method definition.
>
> > import sys
>
> > def getCodeName(deap=0):
> >     return sys._getframe(deap+1).f_code.co_name
>
> > class MyClass (object):
> >     name = getCodeName() + '!'
>
> What's the advantage over MyClass.__name__?
>
> --
> Gabriel Genellina

>>> class C(object):
...     name = C.__name__
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in C
NameError: name 'C' is not defined
>>>




More information about the Python-list mailing list