[issue20992] reading individual bytes of multiple binary files using the Python module fileinput
Tommy Carstensen
report at bugs.python.org
Thu Mar 20 10:39:18 CET 2014
New submission from Tommy Carstensen:
This is my first post on bugs.python.org. I hope I abide to the rules. It was suggested to me on stackoverflow.com, that I request an enhancement to the module fileinput here:
http://stackoverflow.com/questions/22510123/reading-individual-bytes-of-multiple-binary-files-using-the-python-module-filein
I can read the first byte of a binary file like this:
with open(my_binary_file,'rb') as f:
f.read(1)
But when I run this code:
import fileinput
with fileinput.FileInput(my_binary_file,'rb') as f:
f.read(1)
then I get this error:
AttributeError: 'FileInput' object has no attribute 'read'
I would like to propose an enhancement to fileinput, which makes it possible to read binary files byte by byte.
I posted this solution to my problem:
def process_binary_files(list_of_binary_files):
for file in list_of_binary_files:
with open(file,'rb') as f:
yield f.read(1)
return
list_of_binary_files = ['f1', 'f2']
generate_byte = process_binary_files(list_of_binary_files)
byte = next(generate_byte)
----------
components: Library (Lib)
messages: 214195
nosy: Tommy.Carstensen
priority: normal
severity: normal
status: open
title: reading individual bytes of multiple binary files using the Python module fileinput
type: enhancement
versions: Python 3.3, Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20992>
_______________________________________
More information about the Python-bugs-list
mailing list