tqdm.utils#
General helpers required for tqdm.std
.
envwrap#
def envwrap(prefix, types=None, is_method=False)
Override parameter defaults via os.environ[prefix + param_name]
. Maps UPPER_CASE env vars map to lower_case param names. camelCase isn't supported (because Windows ignores case).
Precedence (highest first):
- call (
foo(a=3)
) - environ (
FOO_A=2
) - signature (
def foo(a=1)
)
Parameters
- prefix: str
Env var prefix, e.g. "FOO_" - types: dict, optional
Fallback mappings{'param_name': type, ...}
if types cannot be inferred from function signature. Consider usingtypes=collections.defaultdict(lambda: ast.literal_eval)
. - is_method: bool, optional
Whether to usefunctools.partialmethod
. If (default: False) usefunctools.partial
.
Examples
$ cat foo.py
from tqdm.utils import envwrap
@envwrap("FOO_")
def test(a=1, b=2, c=3):
print(f"received: a={a}, b={b}, c={c}")
$ FOO_A=42 FOO_C=1337 python -c 'import foo; foo.test(c=99)'
received: a=42, b=2, c=99
CallbackIOWrapper Objects#
class CallbackIOWrapper(ObjectWrapper)
disp_len#
def disp_len(data)
Returns the real on-screen length of a string which may contain ANSI control codes and wide chars.
disp_trim#
def disp_trim(data, length)
Trim a string which may contain ANSI control characters.