Interface and Methods#

Each unit is an instance of class Physical, as in “physical quantity”.

Instances of Physical are not typically created through the class constructor but by through multiplication with either numbers (int or float) or other Physical instances.

When the library is imported, and also when an environment is loaded, the namespace is auto-populated with variables representing units, all of which are instances of the Physical class.

Instances of the Physical class are immutable and most operations on a Physical instance produce a new instance.

[18]:
import forallpeople as si
si.environment('default')

API#

The methods defined on Physical allow you to have some control on the representation of the instance.

class forallpeople.Physical(value: float, dimensions: Dimensions, factor: float, precision: int = 3, prefixed: str = '')[source]#

A class that defines any physical quantity that can be described within the BIPM SI unit system.

prefix(prefixed: str = '') Physical[source]#

Return a Physical instance with ‘prefixed’ property set to ‘prefix’ if ‘prefixed’ is set to “unity” then the unit will be forced into its unprefixed state.

property repr: str#

Returns a traditional Python string representation of the Physical instance.

split(base_value: bool = True) tuple[source]#

Returns a tuple separating the value of self with the units of self. If base_value is True, then the value will be the value in base units. If False, then the apparent value of self will be used.

This method is to allow flexibility in working with Physical instances when working with numerically optimized libraries such as numpy which cannot accept non-numerical objects in some of their operations (such as in matrix inversion).

to(unit_name='') Physical | None[source]#

Returns a Physical instance representing self converted into one of the available conversion units for its dimension. If .to() is called without any arguments, then it will return None and instead print a list of available conversion units.