1with open("file.txt") as file_in:
2 lines = []
3 for line in file_in:
4 lines.append(line)
1# Open the file with read only permit
2f = open('my_text_file.txt')
3# use readline() to read the first line
4line = f.readline()
5# use the read line to read further.
6# If the file is not empty keep reading one line
7# at a time, till the file is empty
8while line:
9 # in python 2+
10 # print line
11 # in python 3 print is a builtin function, so
12 print(line)
13 # use realine() to read next line
14 line = f.readline()
15f.close()
16
1# Program to read all the lines in a file using readline() function
2file = open("python.txt", "r")
3while True:
4 content=file.readline()
5 if not content:
6 break
7 print(content)
8file.close()
9
10
11