>>>>> "Gary" == Gary Herron <[EMAIL PROTECTED]> writes:

    Gary> Erik Max Francis wrote:
    >> Pierre Barbier de Reuille wrote: > > >
>>When you need some symbols in your program, what do you use in
    >> Python ?
    >>> 
    >>> For example, an object get a state. This state is more
    >>> readable if expressed as a symbols, for example "opened",
    >>> "closed", "error".  Typically, in C or C++, I would use an
    >>> enum for that: enum OBJECT_STATE { opened, closed, error
    >>> }
    >>> 
    >>> 
    >>
> OPENED, CLOSED, ERROR = range(3)
    >> 
    >> object.state = OPENED
    >> 
    >> 
    Gary> Another similar approach that keeps those values together in
    Gary> a single namespace is this (my favorite):

    Gary>   class State: OPENED, CLOSED, ERROR = range(3)

    Gary> Then you can refer to the values as State.OPENED
    Gary> State.CLOSED State.ERROR

    Gary> The extra clarity (and slight wordiness) of the dotted
    Gary> notation seems, somehow, quite Pythonic to me.

    Gary> Gary Herron

I think Zoran Isailovski has the last word on the topic:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to