What do you use as symbols for Python?
Björn Lindström
bkhl at stp.lingfil.uu.se
Fri Nov 11 17:38:42 EST 2005
Gary Herron <gherron at digipen.edu> writes:
> Another similar approach that keeps those values together in a single
> namespace is this (my favorite):
>
> class State:
> OPENED, CLOSED, ERROR = range(3)
>
> Then you can refer to the values as
> State.OPENED
> State.CLOSED
> State.ERROR
Of course, with this solution you still get this problem:
class State:
OPENED, CLOSED, ERROR = range(3)
class Spam:
EGGS, HAM, TOAST = range(3)
State.ERROR == Spam.TOAST => True
Thus, the solutions using unique objects for each value seems cleaner,
and closer to actual symbols, to me.
I don't see why Python doesn't go all the way and add a real symbol
type, though. I've seen way too many ugly string or integer based
solutions.
--
Björn Lindström <bkhl at stp.lingfil.uu.se>
Student of computational linguistics, Uppsala University, Sweden
More information about the Python-list
mailing list