Can global variable be passed into Python function?
marko at pacujo.net
Sat Mar 1 19:25:51 CET 2014
Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
> It seems to me that he's just assuming that symbols ought to be
> singletons, hence his focus on identity rather than equality.
A practical angle is this: if I used strings as symbols and compared
them with "==", logically I shouldn't define them as constants but
simply use strings everywhere:
self.state = "IDLE"
def connect(self, address):
if self.state == "IDLE":
elif self.state == ...
The principal (practical) problem with that is that I might make a typo
if self.state == "IDLE ":
which could result in some hard-to-find problems. That's why I want get
the help of the Python compiler and always refer to the states through
if self.state == self.IDLE:
More information about the Python-list