best way to have enum-like identifiers?

castironpi at gmail.com castironpi at gmail.com
Wed Mar 12 07:29:47 CET 2008


> > [enums snip]
> Thus, those names are all bound to unique objects, that won't be
> unexpectedly duplicated by some other value.
>
> > but I'm curious if there's a better way of doing this, some kind of
> > enum-like thing or somesuch.
>
> Please try the 'enum' package in the Cheeseshop:

Am I the only one superstitious about putting identifiers in strings?

>  When a well-packaged web of lies has been sold to the masses
... someone sold them.

>>> c= type('Enum',(),{})
>>> [ setattr( c, v, object() ) for v in 'py funcpre funcpost'.split() ]
[None, None, None]
>>> c.funcpost
<object object at 0x00A37478>
>>> c.funcpre
<object object at 0x00A37470>

You don't need them to be ints or anything, do you, like USER_BASE+ 1?



More information about the Python-list mailing list