The pyedb.generic.data_handlers library#
Summary#
Format a number with appropriate decimal places and commas. |
|
Generate a random string |
|
Return a unique list of strings from an element list. |
|
Return a list of strings from a string or a list of strings. |
|
Check if the input is a list, if not, convert it to a list. |
|
Convert an RKM code string to a string with a decimal point. |
|
Convert a |
|
Retrieve units for a value. |
|
Load JSON file to a dictionary. |
Module detail#
- data_handlers.format_decimals(el: int | str) str#
Format a number with appropriate decimal places and commas.
- data_handlers.random_string(length: int = 6, only_digits: bool = False, char_set: str | None = None) str#
Generate a random string
- Parameters:
- length
int Length of the random string. Default value is
6.- only_digitsbool,
optional Whether only digits are to be included. Default is
False.- char_set
str,optional Custom character set to pick the characters from. By default chooses from ASCII and digit characters or just digits if
only_digitsisTrue.
- length
- Returns:
strRandom string of specified length.
- data_handlers.unique_string_list(element_list: str | Iterable[str], only_string: bool = True) list[str]#
Return a unique list of strings from an element list.
- data_handlers.string_list(element_list: str | list) list[str]#
Return a list of strings from a string or a list of strings.
- data_handlers.ensure_list(element_list: Any) list[Any]#
Check if the input is a list, if not, convert it to a list.
- Parameters:
- element_list
Any The input element(s) to be converted to a list.
- element_list
- Returns:
list[Any]A list containing the input element(s).
- data_handlers.from_rkm(code: str) str#
Convert an RKM code string to a string with a decimal point.
Examples
>>> from_rkm("R47") '0.47'
>>> from_rkm("4R7") '4.7'
>>> from_rkm("470R") '470'
>>> from_rkm("4K7") '4.7k'
>>> from_rkm("47K") '47k'
>>> from_rkm("47K3") '47.3k'
>>> from_rkm("470K") '470k'
>>> from_rkm("4M7") '4.7M'
- data_handlers.str_to_bool(s: str) bool | str#
Convert a
"True"or"False"string to its corresponding Boolean value.If the passed arguments are not relevant in the context of conversion, the argument itself is returned. This method can be called using the
map()function to ensure conversion of Boolean strings in a list.The method is not case-sensitive:
Trueis returned if the input is"true","1", “yes”`, or"y";Falseis returned if the input is"false","no","n", or"0".Otherwise, the input value is passed through the method unchanged.
- data_handlers.RKM_MAPS#
- data_handlers.UNIT_VAL#