Improved docs
This commit is contained in:
parent
979e5cc65e
commit
8a016bbd5f
@ -120,6 +120,27 @@ mass.
|
||||
<Quantity(19.0, 'mole')>
|
||||
|
||||
|
||||
Ensuring context when calling a function
|
||||
----------------------------------------
|
||||
|
||||
Pint provides a decorator to make sure that a function called is done within a given
|
||||
context. Just like before, you have to provide as argument the name (or alias) of the
|
||||
context and the parameters that you wish to set.
|
||||
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> wl = 530. * ureg.nm
|
||||
>>> @ureg.with_context('sp', n=1.33)
|
||||
... def f(wl):
|
||||
... return wl.to('Hz').magnitude
|
||||
>>> f(wl)
|
||||
398.496240602
|
||||
|
||||
|
||||
This decorator can be combined with **wraps** or **check** decorators described in `wrapping`_
|
||||
|
||||
|
||||
Defining contexts in a file
|
||||
---------------------------
|
||||
|
||||
|
@ -76,7 +76,8 @@ definitions does not involve changing the code.
|
||||
|
||||
**Advanced string formatting**: a quantity can be formatted into string using
|
||||
`PEP 3101`_ syntax. Extended conversion flags are given to provide symbolic,
|
||||
LaTeX and pretty formatting.
|
||||
LaTeX and pretty formatting. Unit name translation is available if Babel_ is
|
||||
installed.
|
||||
|
||||
**Free to choose the numerical type**: You can use any numerical type
|
||||
(`fraction`, `float`, `decimal`, `numpy.ndarray`, etc). NumPy_ is not required
|
||||
@ -149,3 +150,4 @@ One last thing
|
||||
.. _`uncertainties package`: https://pythonhosted.org/uncertainties/
|
||||
.. _`NumPy`: http://www.numpy.org/
|
||||
.. _`PEP 3101`: https://www.python.org/dev/peps/pep-3101/
|
||||
.. _`Babel`: http://babel.pocoo.org/
|
||||
|
@ -287,7 +287,7 @@ Pint also supports the LaTeX siunitx package:
|
||||
>>> print('The siunitx representation is {:Lx}'.format(accel))
|
||||
The siunitx representation is \SI[]{1.3}{\meter\per\second\squared}
|
||||
|
||||
Finally, you can specify a default format specification:
|
||||
Additionally, you can specify a default format specification:
|
||||
|
||||
.. doctest::
|
||||
|
||||
@ -298,6 +298,14 @@ Finally, you can specify a default format specification:
|
||||
'The acceleration is 1.3 meter/second²'
|
||||
|
||||
|
||||
Finally, if Babel_ is installed you can translate unit names to any language
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> accel.format_babel(locale='fr_FR')
|
||||
'1.3 mètre par seconde²'
|
||||
|
||||
|
||||
Using Pint in your projects
|
||||
---------------------------
|
||||
|
||||
@ -342,3 +350,4 @@ also define the registry as the application registry::
|
||||
|
||||
.. _eval: http://docs.python.org/3/library/functions.html#eval
|
||||
.. _`serious security problems`: http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
|
||||
.. _`Babel`: http://babel.pocoo.org/
|
||||
|
@ -182,8 +182,8 @@ To avoid the conversion of an argument or return value, use None
|
||||
>>> mypp3 = ureg.wraps((ureg.second, None), ureg.meter)(pendulum_period_error)
|
||||
|
||||
|
||||
Checking units
|
||||
==============
|
||||
Checking dimensionality
|
||||
=======================
|
||||
|
||||
When you want pint quantities to be used as inputs to your functions, pint provides a wrapper to ensure units are of
|
||||
correct type - or more precisely, they match the expected dimensionality of the physical quantity.
|
||||
|
Loading…
x
Reference in New Issue
Block a user