Find out if file pointer is at EOF in Python -
i trying find out whether file pointer @ eof in example code: (edited)
f = open("test.dat") somefunctiondoingstuffon_f(f) if f == eof: # keep important in case print "eof reached" else: print "not eof"
but not know if there available in python.
i have edited question adding somefunctiondoingstuffon_f(f), because might not know happened f before hand. excludes approaches.
based on martijns comment can use tell
don't see how going make difference:
import os r.f.seek(0, os.seek_end) n = r.f.tell() r.f.seek(0) while r.f.tell() < n: line = r.f.readline() print(line) print("not @ eof") print("at eof")
where r.f
file object class in previous question cannot use tell in same way using islice.
or using using if's more logic in question:
import os r.f.seek(0, os.seek_end) n = r.f.tell() r.f.seek(0) while true: if r.f.tell() != n: line = r.f.readline() print(line) print("not @ eof") else: print("at eof") break
Comments
Post a Comment