Can global variable be passed into Python function?
ben+python at benfinney.id.au
Sat Mar 1 14:03:32 CET 2014
Marko Rauhamaa <marko at pacujo.net> writes:
> 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.
No. I'm telling you that ‘is’ is *wrong* for comparing strings, because
it is unreliable.
> I prefer a solution that works regardless of what objects I choose for
Some languages have a “symbol” type, whose values can be directly
compared. Python doesn't have such a type. If you want to use strings as
a substitute, go ahead: they work fine.
But compare strings by *equality*, not identity, because it's their
*values* which will be the identifiers. Their object identity will not
be reliably comparable.
That's what everyone has been telling you all along, for reasons already
> There really is no taboo against string object identity if you know what
> you are doing.
You, as has been amply demonstrated, do not, despite your dogmatic
\ “Under democracy one party always devotes its chief energies to |
`\ trying to prove that the other party is unfit to rule — and |
_o__) both commonly succeed, and are right.” —Henry L. Mencken |
More information about the Python-list