This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Tommy.Carstensen
Recipients Tommy.Carstensen
Date 2014-03-20.09:39:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395308358.24.0.394354098821.issue20992@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2014-03-20 09:39:18Tommy.Carstensensetrecipients: + Tommy.Carstensen
2014-03-20 09:39:18Tommy.Carstensensetmessageid: <1395308358.24.0.394354098821.issue20992@psf.upfronthosting.co.za>
2014-03-20 09:39:18Tommy.Carstensenlinkissue20992 messages
2014-03-20 09:39:17Tommy.Carstensencreate