6

我的 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

奇怪的是,异常仅在执行我的整个代码时发生,而不是仅在打开文件的特定部分时发生。在这部分代码的运行时,打开的文件肯定存在,磁盘未满,变量“迭代器”包含一个正确的值,如第一个代码块。我的错误可能是什么?

提前致谢

4

1 回答 1

6

来自lseek(2)

EINVAL

wherece 不是 SEEK_SET、SEEK_CUR、SEEK_END 之一;或者生成的文件偏移量将为负数,或超出可搜索设备的末尾。

因此,请仔细检查 的值iterator

于 2010-04-27T18:51:32.450 回答