Rider.vl0 发表于 2019-7-10 22:15:26

python第30课一个任务,错误ValueError: not enough values to unpack (expected 2...

本帖最后由 Rider.vl0 于 2019-7-10 22:20 编辑

import codecs
f = open("D:\\File\\测试文档.txt",encoding='iso-8859-15')

boy =[]
girl = []
cunoe = 1
for each_sdk in f:
    if each_sdk[:6] != "=======":
      (reo,line_spoken) = each_sdk.split(":",1)
      if reo == "小甲鱼":
            boy.append(line_spoken)
      if reo =="小客服":
            girl.append(line_spoken)
    else:
      name_girl = "girl_"+ str(cunoe) + '.txt'
      name_boy = 'boy_'+ str(cunoe) + '.txt'

      boy_file = open(name_boy,"w")
      girl_file = open(name_girl,'w')

      boy_file.writelines(boy)
      girl_file.writelines(girl)

      boy_file.close()
      girl_file.close()

      boy= []
      girl = []
      cunoe += 1
name_girl = "girl_"+ str(cunoe) + '.txt'
name_boy = 'boy_'+ str(cunoe) + '.txt'

boy_file = open(name_boy,"w")
girl_file = open(name_girl,'w')

boy_file.writelines(boy)
girl_file.writelines(girl)

boy_file.close()
girl_file.close()

f.close()

我自己与视频教学中的代码检查过了没有问题但是报错,求救啊
Traceback (most recent call last):
File "D:\File\新建文本文档.py", line 9, in <module>
    (reo,line_spoken) = each_sdk.split(":",1)
ValueError: not enough values to unpack (expected 2, got 1)

冬雪雪冬 发表于 2019-7-10 22:34:42

if each_sdk[:6] != "=======":
!=后面应该是6个=

Rider.vl0 发表于 2019-7-10 23:00:52

冬雪雪冬 发表于 2019-7-10 22:34
if each_sdk[:6] != "=======":
!=后面应该是6个=

嗯,代码确实可以运行了,但是分割出来的文件内容却为空
页: [1]
查看完整版本: python第30课一个任务,错误ValueError: not enough values to unpack (expected 2...