type-checking support in Python?

Bas wegwerp at gmail.com
Tue Oct 7 12:24:26 CEST 2008


On Oct 7, 8:36 am, Lawrence D'Oliveiro <l... at geek-
central.gen.new_zealand> wrote:
> In message <mailman.2089.1223358567.3487.python-l... at python.org>, Gabriel
>
> Genellina wrote:
> > As an example, in the oil industry here in my country there is a mix of
> > measurement units in common usage. Depth is measured in meters, but pump
> > stroke in inches; loads in lbs but pressures in kg/cm².
>
> Isn't the right way to handle that to attach dimensions to each number?

What they taught me as a physics undergrad is to always convert random
units given as input to SI units as soon as possible, do all your
calculations internally in SI units and (only if really needed)
convert back to arbitrary units on output. Now, 15 years later, I am
still trying to stick to this rule whenever possisble. This convention
allows you to 'forget' about units and save your pre/post-fixes for
the exceptional case:
inch = 0.0254
lenght_inch = some_user_input_in_inch()
length = length_inch * inch

I have heard about some python package which overloads numbers and
calculations to include units (quick google found unum, not sure if
that is the only one). I guess that unless you are dealing with life-
critical equipment or are using extreme programming, this is overkill
(but I guess python is not really the right language for that anyway,
imagine a garbage collection just when you want to launch your
shuttle).

Bas



More information about the Python-list mailing list