Guido van Rossum wrote: > Bizarre (given what I know about zero-length read). But in the above > code, you can replace "if not fp.feof()" with "if line". In other > words, you just have to carry the state over within your program. and if that's too hard, just hide the state in a class: class FileWrapper: def __init__(self, file): self.__file = file self.__line = None def __more(self): # try reading another line if not self.__line: self.__line = self.__file.readline() def eof(self): self.__more() return not self.__line def readline(self): self.__more() line = self.__line self.__line = None return line file = open("myfile.txt") file = FileWrapper(file) while not file.eof(): print repr(file.readline()) </F>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4