python怎么计算文档的行数据库
小文件读取,计算行数count = len(open(filepath,'rU').readlines())大文件读取,计算行数count = -1 for count, line in enumerate(open(thefilepath, 'rU')): pass count += 1count = 0 thefile = open(thefilepath, 'rb') while True: buffer = thefile.read(8192*1024) if not buffer: break count += buffer.count('n') thefile.close( )读取指定行import linecachecount = linecache.getline(filename,linenum)
赞0
踩0