python - how many unread bytes left in a file? -


i read periodically 16-bit frames file, last frame need know if there enough data , file valid format.

f.read(16) 

returns empty string if there no more data more or data if there @ least 1 byte. how can check how many unread bytes left in file?

for that, you'd have know size of file. using file object, following:

f.seek(0, 2) file_size = f.tell() 

the variable file_size contain size of file in bytes. while reading, f.tell() - file_size number of bytes remaining. so:


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -