Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnsupportedOperation: can't do nonzero cur-relative seeks : Python

Tags:

Below is my code, I am using :

with open(r'C:\Users\Manish\Desktop\File5.txt', 'r') as f:
     fo = f.read(20)
     print(fo)
     f.seek(20,1)
     fo = f.read(20)
     print(fo)

But instead of getting next lines from current position, it repeatedly showing me error. Where is the problem in my code ?

like image 567
Manish Pal Avatar asked Oct 26 '18 05:10

Manish Pal


1 Answers

It seems like offset from current stream and end of stream only supported in binary mode. Which you have to open the file with

open(r'C:\Users\Manish\Desktop\File5.txt', 'rb')
like image 56
Xenox Inno Avatar answered Sep 22 '22 03:09

Xenox Inno