Getting a class name
Gabriel Genellina
gagsl-py at yahoo.com.ar
Mon Feb 19 00:11:33 EST 2007
En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman <fuzzyman at gmail.com> escribió:
> [somebody] wrote:
>> >>> > 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__?
>> > I were asking, why do you want a "name" attribute since "__name__"
>> > already exists and has the needed information. And worst, using an
>> > internal implementation function to do such task.
>>
>> This might be useful to avoid metaclass hacks when trying to initialize
>> a class attribute that would require the class name. (my 2 cents)
>
> It's still an ugly hack. :-)
> (But a nice implementation detail to know about none-the-less.)
Having class decorators would be nice...
--
Gabriel Genellina
More information about the Python-list
mailing list