有時候模擬出來的資料檔過大,文字編輯器打不開或開啟過於緩慢,則可以將大檔案分割成小檔案以利操作。
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 20 14:41:43 2021
@author: mlin
"""
big_file_path = 'd:/demo/0000_CPA_Sim_1.sp'
filesize_MB = 100
# Don't Change Code Below-------------------------------------
import os
N = filesize_MB * (2 ** 20)
n = 0
num = 1
data = []
output_dir = os.path.dirname(big_file_path)
with open(big_file_path) as fin:
name = '{}/part0.txt'.format(output_dir)
fout = open(name, 'w')
for i in fin:
if n / N > 1:
print(fout)
fout.close()
name = '{}/part{}.txt'.format(output_dir, num)
fout = open(name, 'w')
num += 1
n = 0
fout.writelines(i)
n += len(i)
(圖一) 分割檔案 |
沒有留言:
張貼留言