Can global variable be passed into Python function?
steve+comp.lang.python at pearwood.info
Sun Mar 2 00:13:22 CET 2014
On Sat, 01 Mar 2014 20:25:51 +0200, Marko Rauhamaa wrote:
> 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
That doesn't follow. There is no logical connection between using named
constants (well, pseudo-constants, constants by convention only) and ==.
You can do both, or neither, or either one, whichever suits you.
You might as well say that when you have float constants:
TAU = 6.283185307179586
that "logically" implies that you are prohibited in asking whether
another float is less than or greater than TAU.
> The principal (practical) problem with that is that I might make a typo
> and write:
> if self.state == "IDLE ":
Then used named constants.
if self.state == IDLE:
See how easy it is? Just replace "is" with == unless you have a good
reason for caring about identity instead of equality.
More information about the Python-list