[Python-Dev] Adding syntax for units of measure

skip at pobox.com skip at pobox.com
Wed Jun 24 06:07:02 CEST 2009


    >> Has anyone added special syntax to allow writing numeric literals with
    >> physical units? So you can write 12m + 34cm, and would get 12.34m.
    ...
    Georg> normally you wouldn't add units to the language itself.
    ...
    Georg> For the interactive shell, using a wrapper that allows simplified
    Georg> input is also a possibility, like IPython's "-profile physics"
    Georg> mode, or something like http://bitbucket.org/birkenfeld/phsh/
    Georg> which allows you to write

    >>>> `1 m` + `12 cm`
    Georg> 1.12 m

Also, check out the magnitude module (in PyPI).  I use it to specify the
units of the computation but allow users to input values using units which
are meaningful to them.  So, for example, if a value has units of time they
could enter 1m or 60s and get the same internal value.

Skip


More information about the Python-Dev mailing list