Skip to content

String parsing to initiate Measurement object #1672

@Cs137

Description

@Cs137

I did not find any information on parsing strings in order to initiate a Measurement object in the pint documentation. The method described for the Quantity object shows an unwanted behaviour and creates a product if ± is used as separator between nominal value and uncertainty. In the case of +/-, a DefinitionSyntaxError is raised.

Example:

import pint

ureg = pint.UnitRegistry()

for item in ['123 g','123 ± 3 g', '123 +/- 3 g']:
    print(ureg(item))

Output:

123 gram
369 gram

---------------------------------------------------------------------------
DefinitionSyntaxError                     Traceback (most recent call last)
Input In [2], in <module>
      3 ureg = pint.UnitRegistry()
      5 for item in ['123 g','123 ± 3 g', '123 +/- 3 g']:
----> 6     print(ureg(item))

...

DefinitionSyntaxError: missing unary operator "/"

I used version 0.20.1 of pint in the example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions