Recommendation for validating Python class data?
Question: I'm looking for recommendations for automated validation of instance variables
in Python objects. The validation should occur immediately upon instantiation
or setting.

For example, imagine a class like:

    
    
    import recordtype
    class TemperatureReading(recordtype.recordtype('TemperatureReading',
                                                   ['lat','long','alt','temp'])):
        pass
    

I'd like to be able to constrain lat to +/- 90, long to +/- 180, alt >=0, and
temp >=0 .

Writing getters and setters seems too un-Pythonic and tedious. Is there a
better way?


Answer: Write getters and setters, but use Python
[properties](http://docs.python.org/2/library/functions.html#property) so that
it's less tedious for the user. You can do some simple metaprogramming,
possibly with a [metaclass](http://stackoverflow.com/a/6581949/344821), to
make it less tedious for the class writer as well.

