fd.seek() IOError: [Errno 22] 无效参数 [英] fd.seek() IOError: [Errno 22] Invalid argument

查看:65
本文介绍了fd.seek() IOError: [Errno 22] 无效参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Python 解释器 (v2.6.5) 在以下代码部分中引发了上述错误:

My Python Interpreter (v2.6.5) raises the above error in the following codepart:

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()

last call is 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

奇怪的是,只有在执行我的整个代码时才会发生异常,而不是只有打开文件的特定部分.在这部分代码运行时,打开的文件肯定存在,磁盘未满,变量迭代器"包含一个正确的值,就像第一个代码块一样.我的错误可能是什么?

The strange thing with this is that the exception occurs just when executing my entire code, not if only the specific part with the file opening. At the runtime of this part of code, the opened file definitely exists, disk is not full, the variable "iterator" contains a correct value like in the first codeblock. What could be my mistake?

提前致谢

推荐答案

来自 lseek(2):

EINVAL

wherece 不是 SEEK_SET 之一,SEEK_CUR,SEEK_END;或由此产生的文件偏移量将是负数,或超出可查找设备的末尾.

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 的值.

这篇关于fd.seek() IOError: [Errno 22] 无效参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆