Python文件数据分割

我说:老师你好,你是教音乐的么?

目前创新互联公司已为上1000+的企业提供了网站建设、域名、雅安服务器托管、网站托管维护、企业网站设计、淮上网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

他说:是的。教音乐修养的

我说:老师,你们的音乐课太无聊了,怎么不多欣赏现代流行音乐呢,非得枯燥的古典乐器?

他说:你安心学吧!

==============================================================================================

她说:快递号?

我说:xxxx

她说:没有!

我说:咋会啊?明明给我发了短信的。

她说:明明发给你的,你去找明明要,别挡着,下一位!5,与以为同学对话

我说:同学,能和你聊聊么?

===============================================================================================

我说:你咋不吃饭呢?

她说:不饿

我说:哦

她说:你去吃吧

我说:哦

她说:快去

我说:哦!

f = open('D:\\桌面\\record.txt',encoding = 'utf-8')

me = []

he = []

she = []

count = 1

for each_line in f:

    if each_line[:6] != '======':

        (role, line_spoken) = each_line.split(':',1)

        if role == '我说':

            me.append(line_spoken)

        if role == '他说':

            he.append(line_spoken)

        if role == '她说':

            she.append(line_spoken)

    else:

        file_name_me = 'Me_' + str(count) + '.txt'

        file_name_he = 'He_' + str(count) + '.txt'

        file_name_she = 'She_' + str(count) + '.txt'

        me_file = open(file_name_me,'w')

        he_file = open(file_name_he,'w')

        she_file = open(file_name_she,'w')

        

        me_file.writelines(me)

        he_file.writelines(he)

        she_file.writelines(she)

        me_file.close()

        he_file.close()

        she_file.close()

        me = []

        he = []

        she = []

        count += 1

file_name_me = 'Me_' + str(count) + '.txt'

file_name_he = 'He_' + str(count) + '.txt'

file_name_she = 'She_' + str(count) + '.txt'

me_file = open(file_name_me,'w')

he_file = open(file_name_he,'w')

she_file = open(file_name_she,'w')

        

me_file.writelines(me)

he_file.writelines(he)

she_file.writelines(she)

me_file.close()

he_file.close()

she_file.close()

f.close()

文章标题:Python文件数据分割
链接地址:https://www.cdcxhl.com/article22/iepejc.html

成都网站建设公司_创新互联,为您提供网站收录标签优化Google软件开发企业建站网站设计公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站建设