type-checking support in Python?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Oct 11 02:54:40 EDT 2008
On Tue, 07 Oct 2008 19:36:12 +1300, Lawrence D'Oliveiro wrote:
> In message <mailman.2089.1223358567.3487.python-list 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?
This thread may be dead by now, but just for the record "dimensions" are
not "units". 1 inch and 1 kilometre have the same dimension (Length) but
obviously they can't be added to make 2 inches (or 2 kilometres).
On the other hand, dimensions are very handy for sanity results; if
somebody suggested to me that adding 15 inch second per gram to 195 cm
month per tonne gave 6.7 gallons per millgram hour, I don't even need to
do the conversion to see that this *must* be wrong because the dimensions
don't match: the original arguments have dimensions Length*Time/Mass but
the supposed argument has dimensions L**3/(M*T).
Dimensions are useful to check if quantities are compatible, but you
still need to convert them to a common unit.
--
Steven
More information about the Python-list
mailing list