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
1fo = open("output.txt", "r+")
2str = fo.readline()
3str = str[7:11]
4print("Read String is : ", str)
5fo.close()
1fo = open("output.txt", "r+")
2str = fo.readline()
3str = str[7:11]
4print "Read String is : ", str
5fo.close()