Can global variable be passed into Python function?

Ben Finney ben+python at
Sat Mar 1 01:50:37 CET 2014

Marko Rauhamaa <marko at> writes:

> Ben Finney <ben+python at>:
> > 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"
> The 5 constants can (and should) be distinguished with the "is"
> operator.

>From each other, of course they're distinct, because they are unequal.

They are *not* necessarily distinct from other strings with equal value,
defined elsewhere. That's what has been pointed out to you many times.

So, either you care about these values being distinct from all others
because you want to compare them with ‘is’ (and so strings are a poor
choice); or you don't care about that, and you should instead compare
these values with the equality operator ‘==’.

Either way, don't compare strings with ‘is’. If you want objects you can
compare reliably with ‘is’, use some other type.

 \     “Don't be afraid of missing opportunities. Behind every failure |
  `\         is an opportunity somebody wishes they had missed.” —Jane |
_o__)                                          Wagner, via Lily Tomlin |
Ben Finney

More information about the Python-list mailing list