What do you use as symbols for Python ?

Antoon Pardon apardon at forel.vub.ac.be
Thu Nov 10 08:19:11 EST 2005


Op 2005-11-10, Pierre Barbier de Reuille schreef <pierre.barbier at cirad.fr>:
> 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



More information about the Python-list mailing list