I'm writing a parser object and I'd like to understand best practice for indicating the end of the file. its seems like the code should look like this.
myFp = newParser(filename) # package opens a file pointer and scans through multiple lines to get an entry
while entry in myFp:
yourCode(entry)
I see that raising an exception is better than returning a status call but this case seems to be handled differently.
Since the parser is reading multiple lines I can't just send the result of readline() back up the code chain, so the while loop runs infinitely in my current implementation.
def read(this):
entry = ''
while 1:
line = this.fp.readline()
if line = '\\':
return entry
else:
entry += line
return entry
Can someone show me how the object is structured on reading so that the while loop exits in this scenario?