Adjusted doc examples to Py3

This commit is contained in:
Hernan Grecco 2013-07-03 01:46:13 -03:00
parent ae05bc94c0
commit 261799e8ff
5 changed files with 14 additions and 14 deletions

View File

@ -68,7 +68,7 @@ You can easily add units to the registry programmatically. Let's add a dog_year
# We create a quantity based on that unit and we convert to years.
>>> lassie_lifespan = Q_(10, 'year')
>>> print(lassie_lifespan.to('dog_years'))
70.238884381 dog_year
70.23888438100961 dog_year
Note that we have used the name `dog_years` even though we have not defined the plural form as an alias. Pint takes care of that, so you don't have to.

View File

@ -46,7 +46,7 @@ Measurements support the same formatting codes as Quantity. For example, to pret
.. doctest::
>>> print('{:.02f!p}'.format(book_length))
(2.00 ± 0.20) meter
(20.00 ± 2.00) centimeter
Mathematical operations with Measurements, return new measurements following the `Propagation of uncertainty`_ rules.

View File

@ -26,14 +26,14 @@ For example, to convert from celsius to fahrenheit:
>>> ureg = UnitRegistry()
>>> home = 25.4 * ureg.degC
>>> print(home.to('degF'))
77.7200004 degF
77.72000039999993 degF
or to other kelvin or rankine:
.. doctest::
>>> print(home.to('degK'))
298.55 degK
298.54999999999995 degK
>>> print(home.to('degR'))
537.39 degR
@ -49,7 +49,7 @@ is different).
>>> print(increase.to(ureg.delta_degK))
12.3 delta_degK
>>> print(increase.to(ureg.delta_degF))
6.83333333333 delta_degF
6.833333333333334 delta_degF
..
Subtraction of two temperatures also yields a *delta* unit.

View File

@ -22,7 +22,7 @@ quantity involving the magnitudes `V`, `T` and `L` with dimensions `[length]/[ti
>>> from pint import pi_theorem
>>> pi_theorem({'V': '[length]/[time]', 'T': '[time]', 'L': '[length]'})
[{'V': 1, 'T': 1, 'L': -1}]
[{'V': 1.0, 'T': 1.0, 'L': -1.0}]
The result indicates that a dimensionless quantity can be obtained by
multiplying `V` by `T` and the inverse of `L`.
@ -44,14 +44,14 @@ you can use derived dimensions such as speed:
>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> ureg.pi_theorem({'V': '[speed]', 'T': '[time]', 'L': '[length]'})
[{'V': 1, 'T': 1, 'L': -1}]
[{'V': 1.0, 'T': 1.0, 'L': -1.0}]
or unit names:
.. doctest::
>>> ureg.pi_theorem({'V': 'meter/second', 'T': 'second', 'L': 'meter'})
[{'V': 1, 'T': 1, 'L': -1}]
[{'V': 1.0, 'T': 1.0, 'L': -1.0}]
or quantities:
@ -59,7 +59,7 @@ or quantities:
>>> ureg.pi_theorem({'V': Q_(1, 'meter/second'),
... 'T': Q_(1, 'second'),
... 'L': Q_(1, 'meter')})
[{'V': 1, 'T': 1, 'L': -1}]
[{'V': 1.0, 'T': 1.0, 'L': -1.0}]
Application to the pendulum
@ -73,7 +73,7 @@ There are 3 fundamental physical units in this equation: time, mass, and length,
... 'M': '[mass]',
... 'L': '[length]',
... 'g': '[acceleration]'})
[{'T': 2, 'g': 1, 'L': -1}]
[{'T': 2.0, 'g': 1.0, 'L': -1.0}]
which means that the dimensionless quantity is:
@ -104,7 +104,7 @@ What is the pressure loss `p` in a pipe with length `L` and diameter `D` for a f
... 'm': '[viscosity]',
... 'v': '[speed]'
... })
[{'p': 1, 'm': -2, 'd': 1, 'L': 2}, {'v': 1, 'm': -1, 'd': 1, 'L': 1}, {'L': -1, 'D': 1}]
[{'p': 1.0, 'm': -2.0, 'd': 1.0, 'L': 2.0}, {'v': 1.0, 'm': -1.0, 'd': 1.0, 'L': 1.0}, {'L': -1.0, 'D': 1.0}]
The second dimensionless quantity is the `Reynolds Number`_

View File

@ -54,7 +54,7 @@ As unit registry knows about the relationship between different units, you can c
.. doctest::
>>> speed.to(ureg.inch / ureg.minute )
<Quantity(7086.61417323, 'inch / minute')>
<Quantity(7086.614173228345, 'inch / minute')>
This method returns a new object leaving the original intact as can be seen by:
@ -68,9 +68,9 @@ If you want to convert in-place (i.e. without creating another object), you can
.. doctest::
>>> speed.ito(ureg.inch / ureg.minute )
<Quantity(7086.61417323, 'inch / minute')>
<Quantity(7086.614173228345, 'inch / minute')>
>>> print(speed)
7086.61417323 inch / minute
7086.614173228345 inch / minute
If you ask Pint to perform and invalid conversion: