1with open("file.txt") as file_in:
2 lines = []
3 for line in file_in:
4 lines.append(line)
1with open('file1.txt','r') as f:
2 listl=[]
3 for line in f:
4 strip_lines=line.strip()
5 listli=strip_lines.split()
6 print(listli)
7 m=listl.append(listli)
8 print(listl)
1file1 = open('myfile.txt', 'r')
2Lines = file1.readlines()
3# usage:
4count = 0
5for line in Lines:
6 count += 1
7 print("Line{}: {}".format(count, line.strip()))
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
1file1 = open('myfile.txt', 'r')#open the file (mode read)
2count = 0 #used to count the lines
3
4for line in Lines:
5 line = file1.readline()#read a single line
6 if not line:
7 break
8 count += 1
9 print("Line{}: {}".format(count, line))#print the lines with their number
10