This tutorial will cover another function of file handling i.e. Reading a file.
For reading a file we need to first open using ‘r’ mode which is used for reading.
file = open("abc.text", "r") print (file.read()) print(file.readline())
read() returns whole string but we can also specify number of character which we want to read.
file.read(4) # read the next 4 data
Reading data by traversing and readline()
file = open("abc.text", "r") print(file.readline()) #we can also print data by looping in file object for d in file: print(d)