Bounds checking

Miki Tebeka miki.tebeka at gmail.com
Fri Mar 18 13:11:26 EDT 2011


> 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)
>             sys.exit()
Not that related to the question. But it's usually better to raise an exception.
Exiting in the middle of a function usually make debugging later more "interesting".

You might find Traits interesting for validation, see http://code.enthought.com/projects/traits/

HTH
--
Miki Tebeka <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com



More information about the Python-list mailing list