Paul McGuire wrote in news:[EMAIL PROTECTED] in
comp.lang.python: 

> 
> class Constants(object)
>     pass
> 
> (I guess value immutability could probably be implemented using clever
> implementations of __setattr__ and such, but is it really worth the 
> bother?).
> 
> Then I defined the context for my LEFT and RIGHT constants, which are
> being created to specify operator associativity, and then my constant
> fields as attributes of that object:
> 
> opAssoc = Constants(object)
> opAssoc.RIGHT = 0
> opAssoc.LEFT = 1
> 

This is nice, but you can cut down on some of the cruft:

class Constants( object ):
  pass
  
Constants.RIGHT = 0
Constants.LEFT = 1

## client code ...
print Constants.LEFT

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to