[issue20992] reading individual bytes of multiple binary files using the Python module fileinput

Josh Rosenberg report at bugs.python.org
Tue Mar 25 00:18:06 CET 2014


Josh Rosenberg added the comment:

On memory: Yeah, it could be if the file didn't include any newline characters. Same problem could apply if a text input file relied on word wrap in an editor and included very few or no newlines itself.

There are non-fileinput ways of doing this, like I said; if you want consistent performance, you'd probably use one of them. For example, using the two arg form of iter:

    from functools import partial

    def bytefileinput(files):
        for file in files:
            with open(filename, "rb") as f:
                yield from iter(partial(f.read, 1), b'')

Still kind of slow, but predictable on memory usage and not to complex.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20992>
_______________________________________


More information about the Python-bugs-list mailing list