Torque

class Torque(value: float | int, unit: str)

Bases: UnitBase

Torque object.

Attributes

unitstr

Symbol of the unit of measurement for torque.

valuefloat or int

Torque numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Torque

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Torque

Converted torque.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Torque instantiation.

>>> from gearpy.units import Torque
>>> T = Torque(1, 'Nm')
>>> T
... 1 Nm

Conversion from newton-meter to kilogram force-meter with inplace = False by default, so it does not override the current value.

>>> T.to('kgfm')
... 0.10197162129779283 kgfm
>>> T
... 1 Nm

Conversion from newton-meter to kilogram force-meter with inplace = True, in order to override the current value.

>>> T.to('kgfm', inplace = True)
... 0.10197162129779283 kgfm
>>> T
... 0.10197162129779283 kgfm
property unit: str

Symbol of the unit of measurement for Torque. It must be a str. Available units are:

  • 'Nm' for newton-meter,

  • 'mNm' for milli-newton-meter,

  • 'mNdm' for milli-newton-decimeter,

  • 'mNcm' for milli-newton-centimeter,

  • 'mNmm' for milli-newton-millimeter,

  • 'kNm' for kilo-newton-meter,

  • 'kNdm' for kilo-newton-decimeter,

  • 'kNcm' for kilo-newton-centimeter,

  • 'kNmm' for kilo-newton-millimeter,

  • 'kgfm' for kilogram force-meter,

  • 'kgfdm' for kilogram force-decimeter,

  • 'kgfcm' for kilogram force-centimeter,

  • 'kgfmm' for kilogram force-millimeter,

  • 'gfm' for gram force-meter,

  • 'gfdm' for gram force-decimeter,

  • 'gfcm' for gram force-centimeter,

  • 'gfmm' for gram force-millimeter.

Returns

str

Symbol of the unit of measurement for torque.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Torque numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Torque numerical value.

Raises

TypeError

If value is not a float or an int.