第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在CSV中寫入函數(shù)的結(jié)果

在CSV中寫入函數(shù)的結(jié)果

回首憶惘然 2021-05-02 00:28:35
我正在嘗試在csv中編寫函數(shù)的結(jié)果。不幸的是,沒有熊貓。csv文件輸入:Hello all well?today is cold!I have not had lunch yetHe does not have many brothers or sisters.We are sick腳本:import reimport csvimport stringwith open('teste_csv.csv', 'r') as f:    file = csv.reader(f)    for line in file:        message = ''.join(line)        def toto(message):            message = message.lower()            p = re.compile('|'.join(map(re.escape, string.punctuation)))            no_punct = p.sub(' ', message)            writer = csv.writer(open('result.csv', 'w'))            for row in no_punct:                writer.writerow(row)                return writer         print(toto(message))在終端上,我有<_csv.writer對象,位于0x7fee60e57c50>,在result.csv中,我只有一行寫為'w'。我希望每一行都在我的result.csv中
查看完整描述

2 回答

?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

您需要將編寫器放在第一個(gè)循環(huán)之外。每次循環(huán)拋出時(shí),它都會打開并重寫文件


您正在定義另一個(gè)問題,并在循環(huán)內(nèi)調(diào)用toto,以便使用最后一個(gè)消息值來調(diào)用它。


import re

import csv

import string


with open('test.csv', 'r') as f:

    file = csv.reader(f)

    writer = csv.writer(open('result.csv', 'w'))

    def toto(message):


        message = message.lower()

        p = re.compile('|'.join(map(re.escape, string.punctuation)))

        no_punct = p.sub(' ', message)

        for row in no_punct:

            writer.writerow(row)

            return writer     

    for line in file:

        print line

        message=''.join(line)


    print(toto(message))


查看完整回答
反對 回復(fù) 2021-05-11
  • 2 回答
  • 0 關(guān)注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號