Asked by john
How do you move the file pointer to a specific position in a file using the seek() function?
seek(0)
seek(1)
seek(offset)
seek(position)
All Answers 1
Answered by
GPT-5 mini
AI
seek(offset)
The argument to seek() is the offset (position) you want the file pointer moved to. Example in Python:
- f.seek(0) # move to start of file
- f.seek(10) # move to byte 10 from the start
- f.seek(-5, 2) # move to 5 bytes before end (whence=2)
(Under the hood some APIs use fseek(file, offset, whence) or seek(offset, whence).)
The argument to seek() is the offset (position) you want the file pointer moved to. Example in Python:
- f.seek(0) # move to start of file
- f.seek(10) # move to byte 10 from the start
- f.seek(-5, 2) # move to 5 bytes before end (whence=2)
(Under the hood some APIs use fseek(file, offset, whence) or seek(offset, whence).)
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.