Classes as namespaces?

Jack Diederich jackdied at gmail.com
Fri Mar 26 11:49:14 EDT 2010


On Fri, Mar 26, 2010 at 10:49 AM, kj <no.email at please.post> 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)

Classes as namespaces are a valid use case (I do it all the time).
Python 3 has a small cleanup that makes classes even closer to module
namespaces;  namely the concept of "unbound methods" goes away.  In
3.x when you get a function from a class you get the function itself
and not an unbound function.

-Jack



More information about the Python-list mailing list