bytesize._size module

Size class, for creating instances of Size objects.

Contains a few documented methods and a number of __*__ methods implementing arithmetic operations. Precise numeric types such as int and Decimal may also occur in some arithmetic expressions, but all occurrances of floating point numbers in arithmetic expressions will cause an exception to be raised.

class bytesize._size.Size(value=0, units=None)

Bases: object

Class for instantiating Size objects.

components(min_value=1, binary_units=True, exact_value=False, max_places=2)

Return a representation of this size, decomposed into a Fraction value and a unit specifier tuple.

Parameters:
  • min_value (A precise numeric type: int, long, or Decimal) – Lower bound for value, default is 1.
  • binary_units (bool) – binary units if True, else SI
  • exact_value (bool) – use largest bytes that allow exact value
Returns:

a pair of a decimal value and a unit

Return type:

tuple of Fraction and unit

Raises SizeValueError:
 

if min_value is not usable

The meaning of the parameters is the same as for _config.StrConfig.

componentsList(binary_units=True)

Yield a representation of this size for every unit, decomposed into a Fraction value and a unit specifier tuple.

Parameters:binary_units (bool) – binary units if True, else SI
convertTo(spec=None)

Return the size in the units indicated by the specifier.

Parameters:spec (a units specifier or Size) – a units specifier
Returns:a numeric value in the units indicated by the specifier
Return type:fractions.Fraction
Raises SizeValueError:
 if unit specifier is non-positive
getString(config)

Return a string representation of the size.

:param SizeConfig config: representation configuration :returns: a string representation :rtype: str

magnitude
Returns:the number of bytes
Return type:Fraction
roundTo(unit, rounding)

Rounds to unit specified as a named constant or a Size.

Parameters:
Returns:

appropriately rounded Size

Return type:

Size

Raises SizeValueError:
 

on unusable arguments

If unit is Size(0), returns Size(0).

Previous topic

bytesize._radix module

Next topic

bytesize._sizes module

This Page