Op 2005-11-10, Pierre Barbier de Reuille schreef <[EMAIL PROTECTED]>:
> 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
> }
>
> In CAML or Haskell I would use the union types:
>
> type ObjectState = Opened | Closed | Error
>
> In Ruby I would use the symbols :
>
> object.state = :opened
> object.state = :closed
> object.state = :error
>
> ... but I don't know what to use in Python !

I sometimes just use a class per symbol

class Opened: pass
class Closed: pass
class Error: pass

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

Reply via email to