On Dec 6, 5:29 pm, Matt Saxton wrote:
> You can use a metaclass for this:
>
> >>> class BaseMeta(type):
> ... def __new__(mcs, name, bases, dict):
> ... dict['key'] = 'Key_for_%s' % name
> ... return type.__new__(mcs, name, bases, dict)
> ...
> >>> class Base:
> ... __met
On 6 December 2011 18:12, Ian Kelly 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,
On Tue, Dec 6, 2011 at 11:12 AM, Ian Kelly wrote:
> If you like, you can also expand classproperty to allow setters and
> deleters like property does.
My mistake, you can't do this. __set__ and __delete__ are only
invoked on instances, not on the class. Get-only class properties are
fine, thoug
On Tue, Dec 6, 2011 at 8:57 AM, Paul Moore wrote:
> I want to set up an inheritance hierarchy. The base class will define
> a string value which should include the class name, but I don't want
> people who inherit from my class to have to remember to override the
> value.
>
> If I do this using a
On 06/12/11 15:57, Paul Moore wrote:
I want to set up an inheritance hierarchy. The base class will define
a string value which should include the class name, but I don't want
people who inherit from my class to have to remember to override the
value.
If I do this using an instance variable, it'
I want to set up an inheritance hierarchy. The base class will define
a string value which should include the class name, but I don't want
people who inherit from my class to have to remember to override the
value.
If I do this using an instance variable, it's reasonably easy:
>>> class Base:
...