[storm] Storm : Multiple fields request
Gerdus van Zyl
gerdusvanzyl at gmail.com
Wed Nov 12 14:23:00 GMT 2008
Nifty. I somehow missed that you can use keyword args without
qualifying the class (Person.name == vs name=) for simple equality.
This will make my code a little less verbose.
Thank you,
Gerdus
On Wed, Nov 12, 2008 at 4:00 PM, Gustavo Niemeyer <gustavo at niemeyer.net> wrote:
> Hey Gerdus,
>
>> Some code that I use to do the same thing:
>>
>> cls = Employee
>> param = { 'age':30,'lastname':'smith' }
>>
>> expressions = []
>> for k in param:
>> v = param[k]
>> if v == "none":
>> v = None
>> if hasattr(cls,k):
>> expressions += [ getattr(cls,k) == v ]
>>
>>
>> sl = store.find(cls,And(*expressions))
>
> Except for the None special handling and the check to see if the class
> has the attribute, you could just do something like:
>
> store.find(cls, **param)
>
> Since something like this works:
>
> store.find(cls, age=30, lastname="smith")
>
> --
> Gustavo Niemeyer
> http://niemeyer.net
>
More information about the storm
mailing list