Python文件數(shù)據(jù)分割

我說(shuō):老師你好,你是教音樂(lè)的么?

目前創(chuàng)新互聯(lián)公司已為上1000+的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、淮上網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

他說(shuō):是的。教音樂(lè)修養(yǎng)的

我說(shuō):老師,你們的音樂(lè)課太無(wú)聊了,怎么不多欣賞現(xiàn)代流行音樂(lè)呢,非得枯燥的古典樂(lè)器?

他說(shuō):你安心學(xué)吧!

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

她說(shuō):快遞號(hào)?

我說(shuō):xxxx

她說(shuō):沒(méi)有!

我說(shuō):咋會(huì)啊?明明給我發(fā)了短信的。

她說(shuō):明明發(fā)給你的,你去找明明要,別擋著,下一位!5,與以為同學(xué)對(duì)話

我說(shuō):同學(xué),能和你聊聊么?

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

我說(shuō):你咋不吃飯呢?

她說(shuō):不餓

我說(shuō):哦

她說(shuō):你去吃吧

我說(shuō):哦

她說(shuō):快去

我說(shuō):哦!

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 == '我說(shuō)':

            me.append(line_spoken)

        if role == '他說(shuō)':

            he.append(line_spoken)

        if role == '她說(shuō)':

            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()

文章標(biāo)題:Python文件數(shù)據(jù)分割
鏈接地址:http://muchs.cn/article22/iepejc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄標(biāo)簽優(yōu)化、Google軟件開(kāi)發(fā)、企業(yè)建站網(wǎng)站設(shè)計(jì)公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)