import csv
import sys
import json
reload(sys)
sys.setdefaultencoding( "utf-8" )
filename="AmazonRaisinResult.txt"
with open (filename,"rb")as f:
votes=[]
#将txt文件读进来,这种评论数据不同于数值型数据
for review in f.readlines():
review=review.strip()
# review=review.decode("gbk")
vote=str(review[-3])+str(review[-2])+str(review[-1])
votes.append(vote)
for i in range(5):
print votes[i]
因为就是一个不规则的,()不像列表那么规则的数据)想要提取每行最后的数据,本来用review[-1],但是结果是按照最后一个字符来取的,没办法,只能按字符一个一个取了连接好。再输出,能想出这么笨的办法也是没谁了。
"D:\Program Files\Anaconda2\python.exe" D:/PythonWork/Sentiment_dict/writeVotes.py
132
83
25
17
17
Process finished with exit code 0