| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
name_file = open('record.txt') 
list_boy = [] 
list_girl = [] 
count = 1 
for i in name_file: 
    if i[:6] != '=========': 
        (role, line_spoken) = i.split(':', 1) 
        if role == '小甲鱼': 
            list_boy.append(line_spoken) 
        if role == '小客服': 
            list_girl.append(line_spoken) 
    else: 
        a = 'boy_' + str(count) + '.txt' 
        b = 'girl_' + str(count) + '.txt' 
 
        new_boy = open(a, 'w') 
        new_girl = open(b, 'w') 
        new_boy.writable(list_boy) 
        new_girl.writable(list_girl) 
        new_girl.close() 
        new_girl.close() 
        count += 1 
        list_boy = [] 
        list_girl = [] 
name_file.close() 
 
我(role, line_spoken) = i.split(':', 1)明明已经切片了为什么ValueError: not enough values to unpack (expected 2, got 1)总是报这个错误,脑壳痛。
 本帖最后由 jackz007 于 2021-12-4 20:10 编辑 
        数一下,引号里是几个 '=',如果不是 6 个就写错了,我数了一下,一共是 9 个,所以,这句代码应该这样改:
 
        也就是把 6 改成 9 就可以了。 
        改完了再试。  
 
 
 |   
 
 
 
 |