Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what python feature is illustrated in this code?

I read Storm ORM's tutorial at https://storm.canonical.com/Tutorial, and I stumbled upon the following piece of code :


store.find(Person, Person.name == u"Mary Margaret").set(name=u"Mary Maggie")

I'm not sure that the second argument of the find method will be evaluated to True/False. I think it will be interpreted as a lambda. If that is true, how can I achieve the same effect in my functions ?

like image 251
Geo Avatar asked May 04 '09 20:05

Geo


1 Answers

Person.name has a overloaded __eq__ method that returns not a boolean value but an object that stores both sides of the expression; that object can be examined by the find() method to obtain the attribute and value that it will use for filtering. I would describe this as a type of lazy evaluation pattern.

In Storm, it is implemented with the Comparable object.

like image 186
Miles Avatar answered Oct 20 '22 00:10

Miles