Can global variable be passed into Python function?
Marko Rauhamaa
marko at pacujo.net
Fri Feb 28 19:11:53 EST 2014
Ben Finney <ben+python at benfinney.id.au>:
> As has been pointed out to you, the whole point here is that string
> objects often *are not* distinct, despite conceptually having distinct
> cretion in the source.
You know full well that this initialization creates references to
distinct objects:
class ABC:
IDLE = "IDLE"
CONNECTING = "CONNECTING"
CONNECTED = "CONNECTED"
DISCONNECTING = "DISCONNECTING"
DISCONNECTED = "DISCONNECTED"
The 5 constants can (and should) be distinguished with the "is"
operator. Using "==" in this case would be slightly misleading.
You could define:
class ABC:
IDLE = None
CONNECTING = 1
CONNECTED = list
DISCONNECTING = MyDisconnecting(9)
DISCONNECTED = float("nan")
without changing the functionality of the state machine (as long as "is"
is used to identify the state).
Marko
More information about the Python-list
mailing list