Skip to content Skip to sidebar Skip to footer

How Is Ndb.stringproperty Equals A Python String?

I have this ndb Model class class foo(ndb.Model): abc = ndb.StringProperty() Now when I used abc like this: if foo.abc == 'a': print 'I'm in!' It gets into the if block and p

Solution 1:

You have to instantiate an instance of class to use properties properly.

classFoo(ndb.Model):
  abc = ndb.StringProperty()

foo = Foo()
foo.abc = 'some val'print foo.abc  # prints 'some val'print foo.abc == 'a'# prints Falseprint Foo.abc == 'a'# prints something not boolean - can't check now.

You are are getting "I'm in!" because ndb properties are overwriting __equal__ operator and returning a non empty object that is treated as True. This is used to make queries like query.filter(foo.abc == 'def')

Post a Comment for "How Is Ndb.stringproperty Equals A Python String?"