Symbols as parameters?

Bearophile bearophileHUGS at lycos.com
Thu Jan 21 10:15:38 CET 2010


Martin Drautzburg, having symbols spread in the namespace is bad. And
too much magic is even worse. You seem to need something like an enum
that must be used with its qualified name, as:
move(direction.up)
That works well unless the symbols name are keywords.

Creating a small class like this (that warns if you give it a string
that contains a keyword) looks not too much hard:
direction = Enum("up", "down", "left", "right")
Or:
direction = Enum("up, down, left, right")
Or:
direction = Enum("up down left right")

Bye,
bearophile



More information about the Python-list mailing list