Style for modules with lots of constants
Rob Williscroft
rtw at freenet.co.uk
Wed Nov 1 14:49:28 EST 2006
Paul McGuire wrote in news:KN42h.561$Qn2.495 at tornado.texas.rr.com in
comp.lang.python:
>>> opAssoc = Constants(object)
>>> opAssoc.RIGHT = 0
>>> opAssoc.LEFT = 1
>> This is nice, but you can cut down on some of the cruft:
>> Constants.LEFT = 1
> One man's cruft is another man's clarity.
:-)
> The reason I used instances
> instead of just the Constants class was so that I could define a
> little more descriptive context for the constants,
Sorry I don't know what you mean here, could I have an example ?
> rather than simply
> a shortcut for importing lots and lots of constant definitions. I
> expect I will want to define some more constants for other parts of
> pyparsing, and the instance scoping helps organize them, that's all.
Again I'm struggling to see how using an instance is any different from
just using the class ?
Rob.
--
http://www.victim-prime.dsl.pipex.com/
More information about the Python-list
mailing list