Matt Hancock
Matt Hancock

Reputation: 4039

Get all units of a particular dimensionality with pint

With pint, how can I filter the units in pint.UnitRegistry by dimensionality? For example, how could I get all units of mass type or of volume type?

Upvotes: 6

Views: 1740

Answers (1)

miradulo
miradulo

Reputation: 29720

I believe you're looking for the get_compatible_units method.

>>> ureg = pint.UnitRegistry()

>>> ureg.get_compatible_units('[mass]')
frozenset({<Unit('electron_mass')>,
           <Unit('atomic_mass_unit')>,
           # .... many more
           <Unit('UK_ton')>,
           <Unit('long_ton')>})

Upvotes: 7

Related Questions