[SciPy-dev] Temperature (and other unit) conversions

Adam Curtis adamadamadamamiadam at gmail.com
Tue Dec 19 10:48:35 CST 2006

Adam Curtis <adamadamadamamiadam <at> gmail.com> writes:

> I think an interesting way too approach unit conversions would be to make 
> actual unit classes (for example: a Temperature class), which would inherit 
> from float and would keep track of what unit was being used so that it could 
> seemlessly convert units together during arithmetic operations of differing 
> unit.
> The idea could be extended to other areas as well. Thoughts? 

Example of how it might work:

x = Temperature(20, "c") #Room temperature
print x
y = x.converto("f")      #Room temperature in Farenheit
print y
print y == x
print Temperature(30, "c") + y #Addition of measurements with different units


20 (c)
xx (f)   #heh, don't know the exact conversion
50 (c)  #First measurement in an operation would be used for the return value

More information about the Scipy-dev mailing list