python中UnsupportedOperation: can't do nonzero cur-relative seeks错误
file=open("E:\\test.txt","r")
words=file.read(10)
print(words)
print(file.tell())
file.seek(4,1)
print(file.tell())
file.close()
会报错,是因为python的文件打开中,没有使用b模式选项打开文件,只允许从文件头开始计算相对位置
访问模式改为rb或rb+即可
如下:
file=open("E:\\test.txt","rb")
words=file.read(10)
print(words)
print(file.tell())
file.seek(4,1)
print(file.tell())
file.close()
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
