【发布时间】:2017-03-02 03:49:48
【问题描述】:
我正在尝试从文本文件中获取标记(单词)并将其从所有标点符号中删除。我正在尝试以下方法:
import re
with open('hw.txt') as f:
lines_after_254 = f.readlines()[254:]
sent = [word for line in lines_after_254 for word in line.lower().split()]
words = re.sub('[!#?,.:";]', '', sent)
我收到以下错误:
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
【问题讨论】:
标签: python string mapreduce nlp special-characters