with open('file name') as f:
for line in f:
print(line)
Following is the old way to read file in python. Just for memo.
After reading all contents of file, 'readline()' method will return empty string as ''. And boolean value of '' is False. As such EOF can be handled.
with open('file name') as f:
while True:
line = f.readline()
if not line:
break
print(line)
No comments:
Post a Comment