告诉我,有没有办法让文件分割比我写的更快?
from threading import Thread
from datetime import datetime
def spliter(name):
now = datetime.now()
print(f"start spliting at : {now.strftime('%H:%M:%S')}")
with open(name, "r") as f:
data = f.readlines()
sep = int(len(data) / 2)
first = """"""
second = """"""
def dd1():
nonlocal first
for i in data[:sep]:
first += i
def dd2():
for i in data[sep:]:
nonlocal second
second += i
t1 = Thread(target=dd1)
t2 = Thread(target=dd2)
t1.start()
t2.start()
t1.join()
t2.join()
file1 = open('first.txt', "w")
file1.write(first)
file2 = open('second.txt', "w")
file2.write(second)
print(f"end spliting at : {now.strftime('%H:%M:%S')}")
if __name__ == '__main__':
spliter('Price WA.txt')


