Can global variable be passed into Python function?
torriem at gmail.com
Sat Mar 1 18:05:37 CET 2014
On 03/01/2014 04:28 AM, Marko Rauhamaa wrote:
> 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, '==' works fine no matter what objects you assign to your state
STATE1 = object()
STATE2 = "testing"
STATE3 = 2
self.state = Foo.STATE1
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
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