我试图读取big data file.txt并拆分所有逗号、点等,因此我用Python读取了包含以下代码的文件:
file= open("file.txt","r")
importantWords =[]
for i in file.readlines():
line = i[:-1].split(" ")
for word in line:
for j in word:
word = re.sub('[\!@#$%^&*-/,.;:]','',word)
word.lower()
if word not in stopwords.words('spanish'):
importantWords.append(word)
print importantWords
它还打印了['\xef\xbb\xbfdataText1', 'dataText2' .. 'dataTextn']
。
我该怎么清洗这个\xef\xbb\xbf
?我正在使用Python2.7。
是UTF-8 encoded BOM。
可以使用^{} 和^{} 跳过BOM序列:
旁注:不要使用
file.readlines
,只要遍历文件即可。file.readlines
将创建不必要的临时列表,如果您只想遍历文件。相关问题 更多 >
编程相关推荐