|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- name=input('请输入你想编辑保存的文件名:')
- import pickle
- def text_split(name):
- num=1
- c=[]
- d=[]
- f=open(name)
- for i in f:
- if i[0:3]=='小客服':
- print(i)
- f.seek(6,1)
- c.append(f.readline)
-
-
- elif i[0:3]=='小甲鱼':
- print(i)
- f.seek(6,1)
- d.append(f.readline())
-
- elif i[0:3]=='===':
- print(i)
- a=open('girl%d.txt'%num,'wb')
- pickle.dump(c,a)
- a.close()
- b=open('boy%d.txt'%num,'wb')
- pickle.dump(d,b)
- b.close()
- num+=1
- print(num)
-
- a=open('girl%d.txt'%num,'wb')
- pickle.dump(c,a)
- a.close()
- b=open('boy%d.txt'%num,'wb')
- pickle.dump(d,b)
- b.close()
- text_split(name)
复制代码
我写的代码,运行后出现:f.seek(6,1)
io.UnsupportedOperation: can't do nonzero cur-relative seeks为什么会出现这个错误?
In text files (those opened without a b in the mode string), only seeks relative to the beginning of the file are allowed (the exception being seeking to the very file end with seek(0, 2)).
意思是对于非二进制的文本文件,不允许使用偏移定位。
|
|