48. # text format
# 201509|74000|1|0|0|500
# time, code, weekend, gender, age, pop
from time import time
filename = input("input text file name : ")
start = int(input("input start range : "))
end = int(input("input end range : "))
with open("out1_" + filename, mode = "w", encoding="UTF-8") as fp1:
with open(filename, mode="r", encoding="UTF-8") as fp2:
startTime = time()
print("calculating file's line number ...")
numLines = sum(1 for line in open(filename))
processTime = time() - startTime
print("done in %.5fs. total %d lines" % (processTime, numLines))
print("start next process ...")
startTime = time()
chunk = int(numLines / 10)
for i in range(numLines):
if i % chunk == 0:
print("%d / %d (%.5f)" % (i, numLines, time() - startTime))
line = fp2.readline()
code = line.split("|")[1]
if start <= code <= end:
fp1.write(line)
processTime = time() - startTime
print("done in %.5f" % processTime)