Answers for "read lines from file"

2

readline in a file

myfile = open("demo.txt", "r")
myline = myfile.readline()
while myline:
    print(myline)
    myline = myfile.readline()
myfile.close()
Posted by: Guest on June-24-2021
0

Read text file line by line using the readline() function

# Program to read all the lines in a file using readline() function
file = open("python.txt", "r")
while True:
	content=file.readline()
	if not content:
		break
	print(content)
file.close()
Posted by: Guest on September-25-2021
0

Which function is used to read single line from file?

# Question: Which function is used to read single line from file?
# Answer: readline()
Posted by: Guest on August-03-2021

Python Answers by Framework

Browse Popular Code Answers by Language