代码如下:
导入时间
def block(file,size=65536):
while True:
nb = file.read(size)
如果不是 nb:
break
产量 nb
def getLineCount(filename):
with open(filename,"r",encoding="utf-8") as f:
return sum(line.count("n") for line in block (f))
if __name__ == "__main__":
import sys
import os
if len(sys.argv) != 2:
print("错误输入参数")
sys.exit(-1)
如果不是 os.path.isfile(sys.argv[1]) :
print(sys.argv " 不是文件")
sys.exit (-1)
start_time = time.time()
print(getLineCount(sys.argv[1]))
print(time.time() - start_time ,"秒")