readline() function in file handling in python by R4R Team

- readline() is a python function used in file handling which read the line of the file one by one.

Syntax-

f=open('myfile.txt','r')
f.readline()


program-

#write data in file in multiple lines
f=open("myfile.txt",'w')
f.write("firstnsecondnthirdnfourthnfive")
f.close()

#read file line by line
f=open("myfile.txt",'r')
print(f.readline())
print(f.readline())
print(f.readline())
print(f.readline())
print(f.readline())
f.close()


output-

first
second
third
fourth
five


-In this program, initially we write into file in multiple lines then by f.readline() return first line and goto second line automatically, so we again print second line and it continue read line one by one and goes to next line.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!