f=open(‘aabb.py’,‘w’)
f.write(b’0123456789abcdef’)
Traceback (most recent call last):
File “<pyshell#1>”, line 1, in
f.write(b’0123456789abcdef’)
TypeError: write() argument must be str, not bytesx=f.write(b’0123456789abcdef’)
Traceback (most recent call last):
File “<pyshell#2>”, line 1, in
x=f.write(b’0123456789abcdef’)
TypeError: write() argument must be str, not bytesx=(b’0123456789abcdef’)
s=str(x)
f.write(s)
19f.seek(5)
5f.seek(1)
1f.seek(-3,2) #此处出现错误是因为在文本文件中,没有使用b模式选项打开的文件,只允许从文件头开始计算相对位置,从文件尾计算时就会引发异常。
Traceback (most recent call last):
File “<pyshell#8>”, line 1, in
f.seek(-3,2)
io.UnsupportedOperation: can’t do nonzero end-relative seeks
以上出现的全部错误改正得f=open(‘aabb.py’,‘rb+’) #以二进制格式打开一个文件用于读写
f.write(b’0123456789abcdef’)
16f.seek(-3,2)
16
seek()异常
猜你喜欢
转载自blog.csdn.net/ingenuou_/article/details/98356578
今日推荐
周排行