Referring to the class name from a class variable where inheritance is involved
Paul Moore
p.f.moore at gmail.com
Tue Dec 6 13:53:03 EST 2011
On 6 December 2011 18:12, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> How about a class property?
>
> class classproperty(object):
> def __init__(self, fget):
> self.__fget = fget
> def __get__(self, instance, owner):
> return self.__fget(owner)
Nice :-) About as heavyweight as a classmethod, though, so it doesn't
buy me much over that (beyond avoiding a set of parens, which isn't a
big deal). Either classmethod or classproperty gives me the key
benefit I'm after, which is avoiding the per-instance overhead,
though.
TBH, this is a huge case of premature optimisation, though, so it's
probably little more than an academic or style question. :-)
Paul
More information about the Python-list
mailing list