Will this do what you need?
def newreadline(f, newlinechar='\0'): c = f.read(1) b = [c] while(c != newlinechar and c != ''): c = f.read(1) b.append(c) return ''.join(b)
EDIT: Added replacement for readlines() :
def newreadlines(f, newlinechar='\0'): line = newreadline(f, newlinechar) while line: yield line line = newreadline(f, newlinechar)
so the OP can do the following:
for line in newreadlines(f, newlinechar='\0'): print(line)
source share