我的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);
Run Code Online (Sandbox Code Playgroud)
最后一个电话是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
Run Code Online (Sandbox Code Playgroud)
奇怪的是,只有在执行我的整个代码时才会发生异常,而不是只有文件打开的特定部分.在这部分代码的运行时,打开的文件肯定存在,磁盘未满,变量"iterator"包含正确的值,就像在第一个代码块中一样.可能是我的错误?
提前致谢
来自lseek(2):
英瓦尔
如果不是SEEK_SET,SEEK_CUR,SEEK_END之一;否则文件偏移量将为负数,或者超出可搜索设备的末尾。
因此,请仔细检查的值iterator。