CKTIS / Python
Data processing pipelines
Connect a source, lazy parsing and selection stages, and a terminal operation that drives consumption.
Version: Python 3.14; repository image, production runtime not attested
Syntax
samples = (int(line) for line in source)Connect a source, lazy parsing and selection stages, and a terminal operation that drives consumption.
Later stages pull values only as needed, so discarding blanks before conversion prevents wasted parsing. A parsing error is raised during consumption and can leave earlier output already processed.
A complete second pass must start from the beginning of the source again.
Examples
def parse(lines):
for line in lines:
if line.strip():
yield int(line)
source = iter([" ", "3", "-1", "4", "bad"])
positive = (n for n in parse(source) if n > 0)
out = []
try:
for n in positive:
out.append(n * 10)
except ValueError:
print(out, "invalid input")
print(sum(parse(["", "2", "3"])))
Result
[30, 40] invalid input 5
A complete second pass must start from the beginning of the source again.