我正在尝试在csv中编写函数的结果。不幸的是,没有熊猫。
csv文件输入:
Hello all well?
today is cold!
I have not had lunch yet
He does not have many brothers or sisters.
We are sick
脚本:
import re
import csv
import string
with 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中
胡子哥哥
相关分类