Can global variable be passed into Python function?

Marko Rauhamaa marko at pacujo.net
Fri Feb 28 11:02:03 CET 2014


Ben Finney <ben+python at benfinney.id.au>:

> There are two reasons why I think this is *still* not a justification
> for using ‘is’ with string values:
>
> 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.
>
> Second reason: This use case is a primary motivation for the Enum
> pattern. The Enum pattern is implemented in the standard-library
> ‘enum’ module, now in Python 3.4
> <URL:http://python.org/dev/peps/pep-0435/>.
>
> So, I think Marko's use case is not a justification for comparing
> string values with ‘is’.

Yes, enums are long overdue. However, since any distinct objects will
do, there is nothing preventing you from using string objects.


Marko

PS On the topic of enums, when are we getting support for a switch
statement?



More information about the Python-list mailing list