Getting a class name

Fuzzyman fuzzyman at gmail.com
Mon Feb 19 15:25:56 EST 2007


On Feb 19, 5:11 am, "Gabriel Genellina" <gagsl... at yahoo.com.ar> wrote:
> En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman <fuzzy... 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...
>

Yes - and Guido said he wouldn't be opposed to the idea when it was
poitned out that they would be very useful for both IronPython and
Jython to implement features of their underlying platforms.

I haven't heard anyone (other than you) mention them recently
though...

Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml

> --
> Gabriel Genellina





More information about the Python-list mailing list