|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
ef lck(a, b, c):
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()
def each(file_name):
f = open('text.txt')
boy = []
girl = []
count = 1
for line in f:
if line[:6] != '======':
(role,spok) = line.split(':',1)
if role == '二哈':
boy.append(spok)
if role == '三哈':
girl.append(spok)
else:
lck(boy, girl, count)
boy = []
girl = []
count += 1
lck(boy, girl, count)
f.close()
each('text.txt')
如果我去掉def each(file_name):调用就可以正常执行,大神帮忙看看。一个文件分割为多份。
原因是你的each(file_name) 去掉file_name 调用改成 each()
|
|