Value API

class odml2.Value(value, unit=None, uncertainty=None)

Create a new value.

If the values value is not a numbers.Number unit and uncertainty are expected to be None.

Parameters:
  • value (bool | float | int | str | datetime | time) – The actual value of the value :-)
  • unit (str) – The SI unit of the value.
  • uncertainty (float) – The uncertainty of the value.
copy(value=None, unit=None, uncertainty=None)

Since values should be treated as immutable objects, the copy() method can be used instead of setting the attributes of the value.

Just assign a modified copy:

v = Value(10, unit="V")
v = v.copy(unit="mV")
Parameters:
  • value (bool | float | int | str | datetime | time) – The actual value of the value (optional)
  • unit (str) – The SI unit of the value (optional)
  • uncertainty (float) – The uncertainty of the value (optional)
Returns:

A (modified) copy of the value.

static from_obj(thing)

Creates a value from all sorts of types of objects.

If the value is a sting like ‘10 +-0.001 mV’ it will be parsed to an equivalent of Value(10, 'mV', 0.001)

Parameters:thing – The object to create a value from.
Returns:The created value object.
Return type:Value
Raises:ValueError if the object can’t be converted to a value.
type

The name of the values data type.

uncertainty
Type:float
unit
Type:str
value
Type:bool | float | int | str | datetime | time

Navigation