know.util¶
Util objects
-
exception
know.util.
IteratorExit
[source]¶ Raised when an iterator should quit being iterated on, signaling this event any process that cares to catch the signal. We chose to inherit directly from
BaseException
instead ofException
for the same reason thatGeneratorExit
does: Because it’s not technically an error.See: https://docs.python.org/3/library/exceptions.html#GeneratorExit
-
class
know.util.
LiveProcess
(streams: Dict[str, Iterable], slab_callback: Callable[[Slab], Any] = <built-in function print>, walk: Callable = <class 'know.util.DictZip'>)[source]¶ -
slab_callback
()¶ print(value, …, sep=’ ‘, end=’n’, file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout. sep: string inserted between values, default a space. end: string appended after the last value, default a newline. flush: whether to forcibly flush the stream.
-
-
class
know.util.
MultiIterable
(*unnamed, stop_condition: Callable[[Any], bool] = <function always_false>, **named)[source]¶ Join several iterables together.
from know.util import any_value_is_none from functools import partial
any_value_is_none = lambda d: any(d[k] is None for k in d) mk_multi_iterable = partial(MultiIterable, stop_condition=any_value_is_none) mi = mk_multi_iterable(lets=’abc’, nums=[1, 2, 3, 4]) list(mi) [{‘lets’: ‘a’, ‘nums’: 1}, {‘lets’: ‘b’, ‘nums’: 2}, {‘lets’: ‘c’, ‘nums’: 3}]
mi = MultiIterable( … x=[5, 4, 3, 2, 1], y=[1, 2, 3, 4, 5], … stop_condition=lambda d: d[‘x’] == d[‘y’] … ) list(mi) [{‘x’: 5, ‘y’: 1}, {‘x’: 4, ‘y’: 2}]
-
know.util.
always_false
(x: Any) → False[source]¶ Returns False, regardless of input. Meant for stopping (filter) functions