Classes as namespaces?
sccolbert at gmail.com
Fri Mar 26 18:36:55 CET 2010
i use them in Pymazon to encapsulate program wide settings and enforce valid
values for these settings.
On Fri, Mar 26, 2010 at 11:50 AM, Jean-Michel Pichavant <
jeanmichel at sequans.com> wrote:
> kj 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)
>> Granted, this is not the "intended use" for classes, and therefore
>> could be viewed as a misuse ("that's what dictionaries are for",
>> etc.). But other than this somewhat academic objection[*], I really
>> can see no problem with using classes in this way.
> You cannot see the problem because there's no problem using classes as
> And yet, I've come across online murky warnings against using
>> classes as "pseudo-namespaces". Is there some problem that I'm
>> not seeing with this technique?
> import this
> Namespaces are one honking great idea -- let's do more of those!
> Modules and dictionaries are no more namespaces than classes. So any
> container is potentially a namespace.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list