untested:

for kid in kids:
   try:
     if eval("kid.%s" % filt):
       setattr(kid, prop, val)
   except:
     pass

   if recurse:
     try:
       kid.setAll(prop, val, recurse=recurse, filt=filt)
     except:
       pass


I think this will be the minimum number of lines of code in any case, but I am 
not sure how try/except:pass compars to  if hasattr() in terms of speed, so it 
may be that if there are many cases that trigger the except it will be slower.


> Note: For a complex filter you have to explicitly use kid.property for the
> second and subsequent clauses...
> 
> For example, if you have a filter set to...
> 
> filt = "property1 == val1 and property2 == val2 and property3 == val3"
> 
> It gets evaluated as "kid.property1 == val2 and property2== val2 and
> property3 == val3" 
> 
> so to get it to work we would have to put...
> 
> filt = "property1 == val1 and kid.property2 == val2 and kid.property3 ==
> val3"
> 

eww.  relying on implementation details.  bad.  not sure what good is.  
guessing 
  eval("kid.%s" % filt) needs to be rewritten to handle your case.

This is better, but kinda klunky:

filt= "%(o)s.property1 == val1 and %(o)s.property2 == val2 and %(o)s.property3"

ok = eval( filt % {'o':'kid'} )

Carl K


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]

Reply via email to