I'm attempting to read and print a .txt
file line-by-line in Python using the readline
function. The below code is intended to print out the entire text file line-by-line, but as of right now, it only prints out the first five lines of the text file.
filename = input("Enter the name and extension of the file you want to open.")
file = open(filename, "r")
fileline = file.readline()
for line in fileline:
fileline = fileline.rstrip("\n")
print(fileline)
fileline = file.readline()
file.close()
I expect the code to print out the entire file line by line, but it currently only prints out the first five lines. What is the bug in the code?