dewloosh.core.tools#
- dewloosh.core.tools.tools.float_to_str_sig(value, *args, sig: int = 6, atol: float = 1e-07, **kwargs) str#
Returns a string representation of a floating point number, with given significant digits.
- Parameters
value (float or a sequence of floats) – A single value, or an iterable.
sig (int) – Number of significant digits.
atol (float) – Floating point tolerance. Values smaller than this in the absolute sense are treated as zero.
- Returns
String representation of the provided input.
- Return type
string or a sequence of strings
Example
Print the value of pi as a string with 4 significant digits:
>>> from dewloosh.core.tools import float_to_str_sig >>> import math >>> float_to_str_sig(math.pi, sig=4) '3.142'
- dewloosh.core.tools.tools.floatformatter(*args, sig: int = 6, **kwargs) str#
Returns a formatter, which essantially a string temapate ready to be formatted.
- Parameters
sig (int, Optional) – Number of significant digits. Default is 6.
- Returns
The string to be formatted.
- Return type
string
Examples
>>> from dewloosh.core import DeepDict >>> data = DeepDict() >>> data['a']['b']['c']['e'] = 1 >>> data['a']['b']['d'] = 2 >>> data.containers()
- dewloosh.core.tools.tools.issequence(arg) bool#
Returns True if arg is any kind of iterable, but not a string, returns False otherwise.
Examples
The formatter to use to print a floating point number with 4 digits:
>>> from dewloosh.core.tools import issequence >>> issequence([1, 2]) True
To print the actual value as a string:
>>> issequence('lorem ipsum') False
- dewloosh.core.tools.dtk.dictparser(d: ~typing.Optional[dict] = None, address=None, *args, dtype=<class 'dict'>, **kwargs)#
Iterates through all the values of a nested dictionary.
Notes
Returns all kinds of items, even nested discionaries themselves, along with their content.
- dewloosh.core.tools.dtk.parseitems(d: ~typing.Optional[dict] = None, *args, dtype=<class 'dict'>, **kwargs)#
A generator function that yields all the items of a nested dictionary as (key, value) pairs.
Notes
Does not return nested dictionaries themselves, only their content.