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