+ 2

After using file.read(). How to take the read cursor back to beginning or to any desired position to start reading from that pos

16th Jun 2017, 8:05 PM
Soumyadeep Mondal
Soumyadeep Mondal - avatar
2 ответов
+ 2
Use file.seek(0) or wherever you want the cursor to go. The seek() method can take 2 parameters. The first (required) is the Byte offset and the second (optional) is the From where (default is 0) 0 = beginning of file, 1 = current cursor location, and 2 = end of file. When seeking from the beginning of the file use positive integers to move the cursor forward X bytes. When seeking from the cursors current location use positive integers to move the cursor forward and negative integers to move the cursor backwards X bytes depending on the cursors current location (I.E. it might already be at the beginning or end of file). When seeking from the end of the file use negative integers to move the cursor backwards X bytes. https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
16th Jun 2017, 9:47 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
This thing is not covered up here. Thanks!!!
16th Jun 2017, 9:58 PM
Soumyadeep Mondal
Soumyadeep Mondal - avatar