加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – fd.seek()IOError:[Errno 22]参数无效

发布时间:2020-12-16 22:23:34 所属栏目:Python 来源:网络整理
导读:我的Python解释器(v2.6.5)在以下代码部分中引发了上述错误: fd = open("some_filename","r")fd.seek(-2,os.SEEK_END) #same happens if you exchange the second arg. w/ 2data=fd.read(2); 最后一个电话是fd.seek() Traceback (most recent call last): Fi

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

奇怪的是,只有在执行我的整个代码时才会发生异常,而不是只有文件打开的特定部分.
在这部分代码的运行时,打开的文件肯定存在,磁盘未满,变量“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.

所以仔细检查迭代器的值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读