Python : File Processing in Python

फ़ाइल ऑब्जेक्ट infile से फ़ाइल की शेष पंक्तियों को पढ़ने के लिए कौन सा फंक्शन है? , Which is the function to read the remaining lines of the file from a file object infile?

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

Which is the function to read the remaining lines of the file from a file object infile?
A. infile.read(2)

B. infile.read()

C. infile.readlines()

D. infile.readline()



Correct Answer :

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 , CCC MCQ Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz career counselling in allahabad Website development Company in Allahabad