[Python-talk] {Python-talk] Running off the end of a file during read?
Bruce Labitt
bruce.labitt at myfairpoint.net
Sun Jun 14 12:24:05 EDT 2009
Folks, I have been coding a binary datalog file reader for a colleague
of mine in the UK. He bought a really cool RS232 datalogger that he
managed to hook up to an ECU (engine control unit). I do a read(56)
because I am looking for a particular sequence. My method works ok for
a file that contains multiple sessions, but fails on the last session (I
suspect) or on a file with ony one session.
Basically I read 56 bytes then look for a sequence in it. If I don't
find it I reset the file pointer so that it is incremented by 1 from the
start of the last 56 byte read. The program keeps going until it finds
the right sequence.
Obviously, if either the sequence is not there, or one hits end of file
things would go haywire (program hang in my case).
Does f.read(n) error if the function hits eof? If not how can I
determine when I hit eof?
Thanks,
Bruce
More information about the Python-talk
mailing list