摘要: 一般的读取文件的方法: with open(file_path, "r") as f: print f.read() 或者 with open(file_path,"r") as f: for line in f.readlines(): print line read()是一次性把文件内容以字符串 阅读全文
posted @ 2016-11-08 15:22 guohuino2 阅读(8180) 评论(0) 推荐(0) 编辑
摘要: time 模块,理解容易 import time time_start = time.time() time_end = time.time() time_use = time_end - time_start 或者 time_start =time.clock() time_use = time. 阅读全文
posted @ 2016-11-08 14:40 guohuino2 阅读(1974) 评论(0) 推荐(0) 编辑
摘要: fd = open("C:\Users\william\Desktop\dup_file - Copy (3).txt","r")for i in fd: print i 耗时 25.6074296742s fd = open("C:\Users\william\Desktop\dup_file - 阅读全文
posted @ 2016-11-08 14:20 guohuino2 阅读(956) 评论(0) 推荐(0) 编辑
摘要: fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0,len(fd.readlines())): print i print fd.readline(), 在研究xrange(0,10000)循环 阅读全文
posted @ 2016-11-08 14:11 guohuino2 阅读(489) 评论(0) 推荐(0) 编辑
摘要: 文件中共有4行内容。 fd = open("C:\Users\william\Desktop\dup_file - Copy (2).txt")for i in xrange(0,5): print type(fd.readline()) print fd.readline() print " " 阅读全文
posted @ 2016-11-08 14:07 guohuino2 阅读(2710) 评论(0) 推荐(0) 编辑
摘要: range(start,stop,step) range(0,8) >>print range(0,8) [0,1,2,3,4,5,6,7] range()返回一个数字列表。 start 默认0,stop不可缺少,step默认为1 xrange(start,stop,step) xrange(0,8 阅读全文
posted @ 2016-11-08 13:33 guohuino2 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 对于很多大文件的增量读取,如果遍历每一行比对历史记录的输钱或者全都加载到内存通过历史记录的索引查找,是非常浪费资源的,网上有很多人的技术博客都是写的用for循环readline以及一个计数器去增量读取,这样是十分脑残的,假如文件很大,遍历一次太久。 我们需要了解获取文件句柄的基本理论,其中包含的指针 阅读全文
posted @ 2016-11-08 11:28 guohuino2 阅读(482) 评论(0) 推荐(0) 编辑