Python三种文件行数读取的方法:
#文件比较小count = len(open(r"d:\lines_test.txt",'rU').readlines())print count#文件比较大count = -1for count,line in enumerate(open(r"d:\lines_test.txt",'rU')):passcount += 1print count#更好的方法count = 0thefile = open(r"d:\lines_test.txt",'rb')while True:buffer = thefile.read(1024 * 8192)if not buffer:breakcount += buffer.count('\n')thefile.close()print count