Skip to content

util

eprint

eprint(*args, **kwargs)

Print to error stream.

Source code in src/metador_core/util/__init__.py
 9
10
11
def eprint(*args, **kwargs):
    """Print to error stream."""
    print(*args, file=sys.stderr, **kwargs)

drop

drop(n: int, it: Iterable)

Drop fixed number of elements from iterator.

Source code in src/metador_core/util/__init__.py
14
15
16
def drop(n: int, it: Iterable):
    """Drop fixed number of elements from iterator."""
    return (x for i, x in enumerate(it) if i >= n)

is_public_name

is_public_name(n: str)

Return whether a name is public (does not start with _).

Source code in src/metador_core/util/__init__.py
19
20
21
def is_public_name(n: str):
    """Return whether a name is public (does not start with _)."""
    return n[0] != "_"

pythonize_name

pythonize_name(name: str)

Sanitize a string to be a valid Python variable name.

Source code in src/metador_core/util/__init__.py
24
25
26
def pythonize_name(name: str):
    """Sanitize a string to be a valid Python variable name."""
    return re.sub(r"\W|^(?=\d)", "_", " ".join(name.split()))