Getting a class name

Gabriel Genellina gagsl-py at yahoo.com.ar
Sun Feb 18 03:17:38 EST 2007


En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <Robert.Katic 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




More information about the Python-list mailing list