i

Python Programming

Python File Position

tell() method tells you current position within the file, in other words, next read or write will occur at that many bytes from beginning of the file.

A seek(offset[, from]) method changes current file position. The offset argument indicates  number of bytes to be moved, from argument specifies reference position from where bytes needs to be moved.

Let’s from is set 0, it means use beginning of the file as reference position and 1 means use  current position as reference position and if set to 2 then end of the file would be taken as ref. position.

Example

Let us take file foo.txt, which we have created above.

Output:

Read String :  Python is

current file position :  10

Again read String  :  Python is