Can global variable be passed into Python function?

Michael Torrie torriem at
Sat Mar 1 18:05:37 CET 2014

On 03/01/2014 04:28 AM, Marko Rauhamaa wrote:
> Ben Finney <ben+python at>:
>> 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, '==' works fine no matter what objects you assign to your state

class Foo(object):
    STATE1 = object()
    STATE2 = "testing"
    STATE3 = 2

    def __init__(self):
        self.state = Foo.STATE1

    def bar(self):
        if self.state == Foo.STATE1:
        elif self.state == Foo.STATE2:
        elif self.state == Foo.STATE3:

> I prefer a solution that works regardless of what objects I choose for
> identifiers.

As shown, '==' does work for this too.  I don't know which is more
correct, but it does work.

More information about the Python-list mailing list