Python文件数据分割

发布时间:2020-07-04 01:57:10 作者:aurtherconan
来源:网络 阅读:920

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

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

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

他说:你安心学吧!

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

她说:快递号?

我说: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()















推荐阅读:
  1. 分割SQL文件
  2. python如何实现文件的分割与合并

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python 文件 数据

上一篇:【学习笔记】AIDL跨应用Service运用

下一篇:Android源码个个击破之6.0蓝牙广播开启源码

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》