Can global variable be passed into Python function?
steve+comp.lang.python at pearwood.info
Sat Mar 1 18:07:16 CET 2014
On Sat, 01 Mar 2014 22:59:52 +1100, Chris Angelico wrote:
> On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa <marko at pacujo.net>
>> Ben Finney <ben+python at benfinney.id.au>:
>>> Use ‘==’, since that's all that matters for getting a value that will
>>> work fine.
>> You are telling me to use '==' if I choose string objects and 'is' if I
>> choose some other objects.
>> I prefer a solution that works regardless of what objects I choose for
>> There really is no taboo against string object identity if you know
>> what you are doing.
> And, as proven here in this thread, you do not know what you are doing.
Steady on, that's a bit harsh. In context, I think that Marko is assuming
that the caller will only ever use the state values via their symbolic
names, e.g. only refer to them as IDLE, CONNECTED etc. and never use
their internal string values "IDLE", "CONNECTED".
I don't think that's a safe assumption, since it requires the caller to
only ever do the right thing, but if it is true, then using "is" in the
way he suggests cannot fail.
Still, I've repeatedly asked Marko to justify why we should care about
the symbols being singletons, and unless I've missed something, he hasn't
even attempted to justify that. It seems to me that he's just assuming
that symbols ought to be singletons, hence his focus on identity rather
More information about the Python-list