Classes as namespaces?
Philip Semanchuk
philip at semanchuk.com
Fri Mar 26 14:10:59 EDT 2010
On Mar 26, 2010, at 1:51 PM, kj wrote:
> Thanks for all your comments.
>
> I see that modules are arguably Python's standard way for implementing
> namespaces. I guess I tend to avoid modules primarily because of
> lingering mental trauma over incidents of insane/bizarro import
> bugs in the past.
There can be good reasons (i.e. unrelated to trauma) not to use a one-
namespace-per-module rule.
For instance, The app I'm working on now has 43 classes defined in a
constants.py file. Each class is just a namespace for constants.
That's much more practical than 43 modules called foo_constants.py,
bar_constants.py, etc.
My Currency(type=CurrencyType.USD, value=decimal.Decimal(".02")),
Philip
More information about the Python-list
mailing list