溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時(shí)間:2020-07-04 01:57:10 來(lái)源:網(wǎng)絡(luò) 閱讀:927 作者:aurtherconan 欄目:編程語(yǔ)言

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

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















向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI