arrow
arrow
arrow
Which of the following method is used to move the file pointer to read the content from a specific position in a text file inside a Python program?
Question

Which of the following method is used to move the file pointer to read the content from a specific position in a text file inside a Python program?

A.

move

B.

tell

C.

find

D.

seek

Correct option is D


In Python, the seek() method is used to move the file pointer to a specific position in a file. This allows you to start reading from any position in the file, not necessarily from the beginning.
Important Key Points:
1. seek(): This method sets the file pointer at a specified position in the file. It takes an argument (the position) and optionally a second argument to specify the reference point (e.g., from the beginning, from the current position, or from the end).
· Example: file.seek(10) moves the pointer to the 10th byte in the file.
2. tell(): This method is used to get the current position of the file pointer, not to move it.
3. find(): This method is used to search for a substring in a string, not for file handling.
4. move: There is no move() method for file pointers in Python. The correct method for repositioning is seek().
Knowledge Booster:
· Option (a): move is not a valid method in Python for file handling.
· Option (b): tell() gives the current file pointer position, but it does not move the pointer. It is used to check where the pointer currently is in the file.
· Option (c): find() is a method used for searching in strings, not for moving the file pointer.

Free Tests

Free
Must Attempt

CDP Subject Test 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt

EVS Subject Test 01

languageIcon English
  • pdpQsnIcon20 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon20 Mins
languageIcon English
Free
Must Attempt

CTET Paper-I PYP (07 July 2024)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
289k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow