马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 LuLD 于 2019-5-2 16:32 编辑 def save_file(boy,girl,count):
file_name_boy='boy'+str(count)+'.txt'
file_name_girl='girl'+str(count)+'.txt'
boy_file=open(file_name_boy,'w')
girl_file=open(file_name_girl,'w')
boy_file.writelines(boy)
girl_file.writelines(girl)
boy_file.close()
girl_file.close()
f = open('Desktop/demo/record.txt')
boy=[]
girl=[]
count=1
for each_line in f:
if each_line[:6] !='== == ==':
(role, line_spoken) = each_line.split(':', 1)
if role=='小甲鱼':
boy.append(line_spoken)
if role=='小客服':
girl.append(line_spoken)
else:
save_file(boy,girl,count)
boy=[]
girl=[]
count+=1
save_file(boy,girl,count)
f.close()
小甲鱼 :
for each_line in f:
if each_line[:6] !='== == ==':
小甲鱼视频里这么写的没有报错,为什么我这么写就会报错
Traceback (most recent call last):
File "E:\Python-test\321\geshi.py", line 14, in <module>
(role,line_spoken) = echo_line.split(':',1)
ValueError: not enough values to unpack (expected 2, got 1)
回溯(最近一次呼叫的最后一次):
文件“e:\python test\321\geshi.py”,第14行,in<module>
(role,line_speaked)=echo_line.split(“:”,1)
ValueError:值不足,无法解包(应为2,得到1)
6个 "=" 之间不可以有任何其他字符。貌似楼主的代码在 "=" 之间有空格存在。
|