Question
Asked By – Gmenfan83
Please excuse my confusion here but I have read the documentation regarding the seek() function in python (after having to use it) and although it helped me I am still a bit confused on the actual meaning of what it does, any explanations are much appreciated, thank you.
Now we will see solution for issue: seek() function?
Answer
Regarding seek()
there’s not too much to worry about.
First of all, it is useful when operating over an open file.
It’s important to note that its syntax is as follows:
fp.seek(offset, from_what)
where fp
is the file pointer you’re working with; offset
means how many positions you will move; from_what
defines your point of reference:
- 0: means your reference point is the beginning of the file
- 1: means your reference point is the current file position
- 2: means your reference point is the end of the file
if omitted, from_what
defaults to 0.
Never forget that when managing files, there’ll always be a position inside that file where you are currently working on. When just open, that position is the beginning of the file, but as you work with it, you may advance.
seek
will be useful to you when you need to walk
along that open file, just as a path you are traveling into.
This question is answered By – Nicolás Ozimica
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0