conversions.prefix_conversions_string ===================================== .. py:module:: conversions.prefix_conversions_string .. autoapi-nested-parse:: * Author: Manuel Di Lullo (https://github.com/manueldilullo) * Description: Convert a number to use the correct SI or Binary unit prefix. Inspired by prefix_conversion.py file in this repository by lance-pyles URL: https://en.wikipedia.org/wiki/Metric_prefix#List_of_SI_prefixes URL: https://en.wikipedia.org/wiki/Binary_prefix Attributes ---------- .. autoapisummary:: conversions.prefix_conversions_string.T Classes ------- .. autoapisummary:: conversions.prefix_conversions_string.BinaryUnit conversions.prefix_conversions_string.SIUnit Functions --------- .. autoapisummary:: conversions.prefix_conversions_string.add_binary_prefix conversions.prefix_conversions_string.add_si_prefix Module Contents --------------- .. py:class:: BinaryUnit(*args, **kwds) Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: exa :value: 60 .. py:attribute:: giga :value: 30 .. py:attribute:: kilo :value: 10 .. py:attribute:: mega :value: 20 .. py:attribute:: peta :value: 50 .. py:attribute:: tera :value: 40 .. py:attribute:: yotta :value: 80 .. py:attribute:: zetta :value: 70 .. py:class:: SIUnit(*args, **kwds) Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:method:: get_negative() -> dict :classmethod: Returns a dictionary with only the elements of this enum that has a negative value @example >>> from itertools import islice >>> negative = SIUnit.get_negative() >>> inc = iter(negative.items()) >>> dict(islice(inc, len(negative) // 2)) {'deci': -1, 'centi': -2, 'milli': -3, 'micro': -6, 'nano': -9} >>> dict(inc) {'pico': -12, 'femto': -15, 'atto': -18, 'zepto': -21, 'yocto': -24} .. py:method:: get_positive() -> dict :classmethod: Returns a dictionary with only the elements of this enum that has a positive value >>> from itertools import islice >>> positive = SIUnit.get_positive() >>> inc = iter(positive.items()) >>> dict(islice(inc, len(positive) // 2)) {'yotta': 24, 'zetta': 21, 'exa': 18, 'peta': 15, 'tera': 12} >>> dict(inc) {'giga': 9, 'mega': 6, 'kilo': 3, 'hecto': 2, 'deca': 1} .. py:attribute:: atto :value: -18 .. py:attribute:: centi :value: -2 .. py:attribute:: deca :value: 1 .. py:attribute:: deci :value: -1 .. py:attribute:: exa :value: 18 .. py:attribute:: femto :value: -15 .. py:attribute:: giga :value: 9 .. py:attribute:: hecto :value: 2 .. py:attribute:: kilo :value: 3 .. py:attribute:: mega :value: 6 .. py:attribute:: micro :value: -6 .. py:attribute:: milli :value: -3 .. py:attribute:: nano :value: -9 .. py:attribute:: peta :value: 15 .. py:attribute:: pico :value: -12 .. py:attribute:: tera :value: 12 .. py:attribute:: yocto :value: -24 .. py:attribute:: yotta :value: 24 .. py:attribute:: zepto :value: -21 .. py:attribute:: zetta :value: 21 .. py:function:: add_binary_prefix(value: float) -> str Function that converts a number to his version with Binary prefix @input value (an integer) @example: >>> add_binary_prefix(65536) '64.0 kilo' .. py:function:: add_si_prefix(value: float) -> str Function that converts a number to his version with SI prefix @input value (an integer) @example: >>> add_si_prefix(10000) '10.0 kilo' .. py:data:: T