读取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
相关文章推荐
- matlab中如何读取TXT数据文件中指定行的数据?
- 用流来读取TXT文件中的数据
- VC读取TXT文件数据(1)
- java读取txt文件中的数据
- 设计一个学生类,其中包含学号、姓名、成绩等数据成员,创建学生对象并且倒入到文件file.txt,然后由文件读取到另一个学生对象并输出,试编程实现。
- 在j2me中读取txt文件数据
- java 读取txt文件中的列表数据 代码
- C编写以二进制读取文件(任意格式eg :图片),保存到C语言数据格式的TXT文档
- Matlab中如何读取TXT数据文件[转载]
- C#控制台控制台将一个文件夹中的所有txt文件中的数据读取出来
- 读取TXT文件,循环显示本行数据
- VB中如何读取txt文件的数据
- C++读取以空格作为数据区分标记,以回车为行标记的txt文件到一个整数数组(字符串妙用)
- C++利用CStdioFile从txt文件中读取数据
- matlab处理txt文本文件---数据格式要有规律性,否则要用编写特定方式进行读取
- 在j2me中读取txt文件数据
- matlab中如何读取TXT数据文件
- matlab中读取txt数据文件(txt文本文档)
- Silverlight 导入数据时读取txt文件乱码
- 9-18 ASP第二讲实现数据的真实操作,从txt文件中读取进行校对,判断登陆是否成功