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.tools.suppress(fnc: Callable) Callable#
Decorator that wraps a function to suppress it’s calls to print.