Classes as namespaces?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon Apr 12 12:31:38 CEST 2010

Aahz a écrit :
> In article <hoihgt$p6t$1 at>, kj  < at> wrote:
>> What's the word on using "classes as namespaces"?  E.g.
>> class _cfg(object):
>>    spam = 1
>>    jambon = 3 
>>    huevos = 2
>> breakfast = (_cfg.spam, _cfg.jambon, _cfg.huevos)
> There is one gotcha associated with using classes as namespaces: you have
> to be careful to avoid instantiating them.  That goes triple if you
> modify the class attributes, because modifying an attribute in an
> instance does *not* propagate the change to the class.

This can be "solved" (using only classmethods and overriding 
__setattr__), but then it begins to be a bit OOTP for a mostly simple 

More information about the Python-list mailing list