Can global variable be passed into Python function?

Ben Finney ben+python at benfinney.id.au
Fri Feb 28 18:17:10 EST 2014


Marko Rauhamaa <marko at pacujo.net> writes:

> Ben Finney <ben+python at benfinney.id.au>:
>
> > First reason: This is better done by making it clear the value is an
> > arbitrary object that won't be compared for equality. Just use
> > ‘object()’ to creeate each value and be done with it. That's a hack,
> > but it's better than pretending you'll use the string as a string of
> > text and then breaking that expectation.
[…]
> > So, I think Marko's use case is not a justification for comparing
> > string values with ‘is’.
>
> […] However, since any distinct objects will do, there is nothing
> preventing you from using string objects.

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.

That's why an ‘object()’ invocation is recommended: because it *will*
create distinct objects. Strings do not have that property. So strings
are *not* suitable for this use case.

-- 
 \     “It is hard to believe that a man is telling the truth when you |
  `\      know that you would lie if you were in his place.” —Henry L. |
_o__)                                                          Mencken |
Ben Finney




More information about the Python-list mailing list