From 69ed5a442df01d0ad2694f3af130618ff87eabac Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jun 2024 10:01:29 +0100 Subject: [PATCH 1/3] add note on symbols to currency docs --- docs/advanced/currencies.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/advanced/currencies.rst b/docs/advanced/currencies.rst index 26b66b531..436abfd0f 100644 --- a/docs/advanced/currencies.rst +++ b/docs/advanced/currencies.rst @@ -84,3 +84,15 @@ currency on its own dimension, and then implement transformations:: More sophisticated formulas, e.g. dealing with flat fees and thresholds, can be implemented with arbitrary python code by programmatically defining a context (see :ref:`contexts`). + +Currency Symbols +---------------- + +Many common currency symbols are not supported by the pint parser. A preprocessor can be used as a workaround: + +.. code-block:: python + ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("€", "EUR")]) + ureg.define("euro = [currency] = € = EUR") + + print(ureg.Quantity("1 €")) + >>> 1 EUR From 9eefa47fca4c9ffca7bcb5052e8323aa03fc0190 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jun 2024 10:22:11 +0100 Subject: [PATCH 2/3] add note on symbols to currency docs --- docs/advanced/currencies.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/advanced/currencies.rst b/docs/advanced/currencies.rst index 436abfd0f..b9b3b295e 100644 --- a/docs/advanced/currencies.rst +++ b/docs/advanced/currencies.rst @@ -90,9 +90,10 @@ Currency Symbols Many common currency symbols are not supported by the pint parser. A preprocessor can be used as a workaround: -.. code-block:: python - ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("€", "EUR")]) - ureg.define("euro = [currency] = € = EUR") +.. doctest:: - print(ureg.Quantity("1 €")) - >>> 1 EUR + >>> import pint + >>> ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("€", "EUR")]) + >>> ureg.define("euro = [currency] = € = EUR") + >>> print(ureg.Quantity("1 €")) + 1 EUR From 3297ab1382c9c47d8c5f722e0e769c93bda55af6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jun 2024 10:39:13 +0100 Subject: [PATCH 3/3] add note on symbols to currency docs --- docs/advanced/currencies.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/currencies.rst b/docs/advanced/currencies.rst index b9b3b295e..addc94785 100644 --- a/docs/advanced/currencies.rst +++ b/docs/advanced/currencies.rst @@ -96,4 +96,4 @@ Many common currency symbols are not supported by the pint parser. A preprocesso >>> ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("€", "EUR")]) >>> ureg.define("euro = [currency] = € = EUR") >>> print(ureg.Quantity("1 €")) - 1 EUR + 1 euro