I have a script generated with 2to3.
With “python3” shebang file.seek gives error.
“io.UnsupportedOperation: can’t do nonzero cur-relative seeks”
The very same script with “python2.7” shebang works.
Message sounds non-sensical to me non-zero current-relative seek is the useful kind, and the zero relative seek is a noop.
I would like to get proper Python3 script to work.
Any help will be much appreciated.
In text files (those opened without a b in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with seek(0, 2) ) and the only valid offset values are those returned from the f.tell() , or zero. Any other offset value produces undefined behaviour.
If your file is not UTF-8, you can open it in 'b’inary mode and seek() around.