I want to change the file position from the current file position to another position.Suppose my current file position is 13 and I want to change this file position to the 18.
I use the seek()
method as follow but it shows some error.
Code:-
fileobj = open("intro.txt","r");
content = fileobj.read(13);
pos = fileobj.tell();
print("Current position : ",pos);
fileobj.seek(5,1); #Change position from current position to next five character.
Error
fileobj.seek(5,1);
io.UnsupportedOperation: can't do nonzero cur-relative seeks
I use python 3.4.3.How can I do this?
Your code works in Python 2, but not in 3. You must open the file as binary:
fileobj = open("intro.txt","rb");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With