Bounds checking

Terry Reedy tjreedy at udel.edu
Fri Mar 18 22:27:20 EDT 2011


On 3/18/2011 10:24 AM, Martin De Kauwe wrote:

> def bounds_check(state):
>      """ check state values are>  0 """
>      for attr in dir(state):
>          if not attr.startswith('__') and getattr(state, attr)<  0.0:
>              print "Error state values<  0: %s" % (attr)

dir() has to do a bit a computation. I would be tempted to give 'state' 
a set of attributes to check. Call it 'nonnegatives'.
    for attr in nonnegatives:
       if ...

This allows for attributes not subject to that check.

-- 
Terry Jan Reedy




More information about the Python-list mailing list