I read periodically 16-bit frames from a file,
last frame I need to know if there are enough data and file is valid for my format.
f.read(16)
returns an empty string if there is no more data more or data if there is at least 1 byte.
How can I check how many unread bytes are left in a file?
For that, you’d have to know the size of the file. Using the file object, you could do the following:
The variable
file_sizewill then contain the size of your file in bytes. While reading, simply dof.tell() - file_sizeto get the number of bytes remaining. So: