A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-June/090189.html below:

[Python-Dev] Adding syntax for units of measure

[Python-Dev] Adding syntax for units of measure [Python-Dev] Adding syntax for units of measureChristian Heimes lists at cheimes.de
Tue Jun 23 12:51:55 CEST 2009
Tobias C. Rittweiler schrieb:
> Hi!
> 
> Has anyone added special syntax to allow writing numeric literals with
> physical units? So you can write 12m + 34cm, and would get 12.34m.
> 
> My question is how would you modify the BNF the most sensible way to
> allow for this? The above example is simple, but think of 42 km/h.

You don't need special syntax in order to work with units. You just need
to normalize all input to SI units like meter, second and meter per second:

km=1000.
m=1.
dm=0.1
cm=0.01
mm=0.001

s= 1.
h = 3600.

m_s=m/s
km_h=km/h

length_in_mm = (12*m + 34*cm)/mm
speed = 5*km_h


For what purpose do you want to have physical units in Python syntax? Do
you need to verify your formulas?

Christian

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4