On 03/01/2014 04:28 AM, Marko Rauhamaa wrote:
> Ben Finney <[email protected]>:
>
>> 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
variables.
class Foo(object):
STATE1 = object()
STATE2 = "testing"
STATE3 = 2
def __init__(self):
self.state = Foo.STATE1
def bar(self):
if self.state == Foo.STATE1:
pass
elif self.state == Foo.STATE2:
pass
elif self.state == Foo.STATE3:
pass
> 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.
--
https://mail.python.org/mailman/listinfo/python-list