py_everything.conversion

Source code: py_everything/conversion.py

This module conatins classes for conversion like, Mass, Length, etc. And it deals with conversion of units.

class py_everything.conversion.Mass(unit, amount)

This class is used for creating an object for Mass values and units

>>> from py_everything.conversion import Mass, convert
>>> from py_everything.units import mg, g
>>> mymass = Mass(units.mg(), 1000)
>>> mymass2 = Mass(units.g(), 1000)
>>> converted = convert(mymass, mymass2)
>>> converted
1.0
Parameters
  • unit (Union) – Any mass unit class from units module.

  • amount (int) – Value of unit.

Note

Even though amount is given input to both Mass classes, the amount in fromType is only used.

class py_everything.conversion.Volume(unit, amount)

This class is used for creating an object for Volume values and units

>>> from py_everything.conversion import Volume, convert
>>> from py_everything.units import l, ml
>>> mymass = Mass(units.l(), 1)
>>> mymass2 = Mass(units.ml(), 1)
>>> converted = convert(mymass, mymass2)
>>> converted
1000.0
Parameters
  • unit (Union) – Any volume unit class from units module.

  • amount (int) – Value of unit.

Note

Even though amount is given input to both Volume classes, the amount in fromType is only used.

class py_everything.conversion.Length(unit, amount)

This class is used for creating an object for Length values and units

>>> from py_everything.conversion import Length, convert
>>> from py_everything.units import mm, m
>>> mymass = Mass(units.mm(), 500)
>>> mymass2 = Mass(units.m(), 1000)
>>> converted = convert(mymass, mymass2)
>>> converted
0.5
Parameters
  • unit (Union) – Any length unit class from units module.

  • amount (int) – Value of unit.

Note

Even though amount is given input to both Length classes, the amount in fromType is only used.

py_everything.conversion.convert(fromType, toType)

Converts value from unit to another.

Parameters
  • fromType (Union) – Unit to convert from.

  • toType (Union) – Unit to convert to.

Returns float

Value after conversion.