Seeking from end of file throwing unsupported exception
问题 I have this code snippet and I\'m trying to seek backwards from the end of file using python: f=open(\'D:\\SGStat.txt\',\'a\'); f.seek(0,2) f.seek(-3,2) This throws the following exception while running: f.seek(-3,2) io.UnsupportedOperation: can\'t do nonzero end-relative seeks Am i missing something here? 回答1: From the documentation for Python 3.2 and up: 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