我的 Python 解释器 (v2.6.5) 在以下代码部分引发了上述错误:
fd = open("some_filename", "r")
fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2
data=fd.read(2);
最后一次调用是 fd.seek()
Traceback (most recent call last):
File "bot.py", line 250, in <module>
fd.seek(iterator, os.SEEK_END);
IOError: [Errno 22] Invalid argument
奇怪的是,异常只是在执行我的整个代码时发生,而不是仅在打开文件的特定部分发生。 在这部分代码的运行时,打开的文件肯定存在,磁盘未满,变量“iterator”包含正确的值,如第一个代码块。 我的错误可能是什么?
提前致谢
最佳答案
来自 lseek(2)
:
EINVAL
whence is not one of SEEK_SET, SEEK_CUR, SEEK_END; or the resulting file offset would be negative, or beyond the end of a seekable device.
所以仔细检查iterator
的值。
关于python - fd.seek() IOError : [Errno 22] Invalid argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2724015/