在python中使用字符串分片时遇到这个问题
[ValueError: not enough values to unpack (expected 2, got 1)]
-------------->>[ 值错误:没有足够的值剖解(期望2,获得1)]
【原码如下】
------------------------------------
f = open('E:\\PYTHON\\talking.txt',encoding = 'utf-8')
boy = []
girl = []
count = 1
for each_line in f:
if each_line[:6] != '======': (people,line_talk) = each_line.split(':',1)
if people == 'OLIVER':
boy.append(line_talk)
if people == '赵琳🍒':
girl.append(line_talk)
else:
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 = []
girl = []
count +=1
----------------------------------
1.文本中的 “:”为英文。细节很重要。
2.首先你要确保文本中不含空行,如qq直接粘贴来的聊天记录会有【如下图】。你要把它去掉,我手动去的很痛苦............
3.文本要紧凑【如下图】,如上图中 ”昵称‘’ 和对应的 ‘’台词‘’ 其实是两行,python会分别读取。造成‘’台词“行没有分隔符 “ :”
4.大功告成!