|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pickle
def split(file):
f = open(file)
boy_word = []
girl_word = []
count = 0
for each_line in f:
if each_line[:6] != '======':
(name, word) = each_line.split(':', 1)
if name == '小甲鱼':
boy_word.append(word)
if name == '小客服':
girl_word.append(word)
else:
count += 1
file1 = 'boy_' + str(count), + '.txt'
file2 = 'girl_' + str(count), + '.txt'
file_boy = open(file1, 'wb')
file_girl = open(file2, 'wb')
pickle.dump(boy_word, file_boy)
pickle.dump(girl_word, file_girl)
file_boy.close()
file_girl.close()
boy_word = []
girl_word = []
count += 1
file1 = 'boy_' + str(count), + '.txt'
file2 = 'girl_'+ str(count), + '.txt'
file_boy = open(file1, 'wb')
file_girl = open(file2, 'wb')
pickle.dump(boy_word, file_boy)
pickle.dump(girl_word, file_girl)
file_boy.close()
file_girl.close()
f.close()
temp = input('请输入需要分割的文件名:')
split(temp)
Traceback (most recent call last):
File "C:\Users\10835\Desktop\python\IDLE.py", line 37, in <module>
split(temp)
File "C:\Users\10835\Desktop\python\IDLE.py", line 16, in split
file1 = 'boy_' + str(count), + '.txt'
TypeError: bad operand type for unary +: 'str'
我的程序运行报出这种错误怎么修改呀。我和作业比对了一下,感觉没啥问题呀?
|
|