Classes as namespaces?
Steve Holden
steve at holdenweb.com
Sat Mar 27 08:22:17 EDT 2010
J. Clifford Dyer wrote:
> On Fri, Mar 26, 2010 at 02:49:02PM +0000, kj wrote regarding Classes
> as namespaces?:
>> 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)
>>
[...]
> I also would not assign integers to spam, jambon, or huevos. Instead
> I would assign each a bare object(). That way you won't get
> unexpected interactions with other constants outside the class. An
> object() is equal only to itself.
>
It also has the advantage (?) that you can use "is" (identity)
comparisons rather than testing for equality, though this is only a
readability issue, I suspect.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/
More information about the Python-list
mailing list