NIELIT O Level Exam

Which is the function to read the remaining lines of the file from a file object infile?

Which is the function to read the remaining lines of the file from a file object infile?

फ़ाइल ऑब्जेक्ट infile से फ़ाइल की शेष पंक्तियों को पढ़ने के लिए कौन सा फंक्शन है?

A. infile.read(2)

B. infile.read()

C. infile.readlines()

D. infile.readline()




Correct Answer is :

C. infile.readlines()



Explanation

In Python, to read the remaining lines of a file from a file object (infile), you can use the readlines() method. The readlines() method reads all the lines of a file and returns a list where each element of the list is a line from the file. If you have already read some lines from the file using methods like readline() or read(), calling readlines() will continue reading the remaining lines.

# Open the file in read mode
with open('your_file.txt', 'r') as infile:
    # Read the remaining lines using readlines()
    remaining_lines = infile.readlines()
# Now, remaining_lines is a list containing all the lines in the file
print(remaining_lines)


CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad