Python readfile¶
fh = open('my_text_file.txt')
while True:
# read line
line = fh.readline()
# in python 2, print line
# in python 3
print(line)
# check if line is not empty
if not line:
break
fh.close()
fh = open('my_text_file.txt')
while True:
# read line
line = fh.readline()
# in python 2, print line
# in python 3
print(line)
# check if line is not empty
if not line:
break
fh.close()