您的位置:首页 > 编程语言 > Python开发

读取TXT文件中的最后一个数据

2017-05-10 16:51 190 查看
import csvimport sysimport jsonreload(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.py13283251717Process finished with exit code 0

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python