Unsupportedoperation can't do nonzero end-relative seeks

According to docs you cant seek the end of a file without the beginning for python 3. Python 3 only supports text file seeks from the beginning of the file. The existing answers do answer the question, but provide no. If you want to get the last three lines of a file, you can use deque f, 3 to iterate over just those lines. But id really like to start migrating to python 3 its only been out for. Read a text file backwards yet another implementation. I want to change the file position from the current file position to another position. Stringio under python 2 and makes some use of the objects relative seek method, with statements like flob.

Stringio object in python 3 does not support relative seeks, so the code raises. Unfortunately, the seek method of the corresponding io. Seeking from end of file throwing unsupported exception stack. Ioerror when attempting negative seek in file python. In text files those opened without a b in the mode string, only seeks relative to the beginning of the file os. Suppose my current file position is and i want to change this file position to the 18.

The file pointer is at the end of the file if the file exists. In text files those opened without a b in the mode string, only seeks. Minor change to hettingers post to get around limitations with io. Seeking from end of file throwing unsupported exception. In text files those opened without a b in the mode string.

994 313 1527 90 666 1561 705 1550 470 245 600 1613 522 1279 190 570 1518 35 1617 41 183 951 959 1281 177 430 1365 1217 1386 408 1384 1090 982 262 27