MCPcopy Index your code
hub / github.com/dabeaz/python-cookbook / combine

Function combine

src/2/combining_and_concatenating_strings/example.py:22–32  ·  view source on GitHub ↗
(source, maxsize)

Source from the content-addressed store, hash-verified

20
21# (c) Combination of parts into buffers and larger I/O operations
22def combine(source, maxsize):
23 parts = []
24 size = 0
25 for part in source:
26 parts.append(part)
27 size += len(part)
28 if size > maxsize:
29 yield ''.join(parts)
30 parts = []
31 size = 0
32 yield ''.join(parts)
33
34for part in combine(sample(), 32768):
35 sys.stdout.write(part)

Callers 1

example.pyFile · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected