def read_large_file(m_fr):
"""
生成器函数,按行读取大文件
:param m_fr:
:return: 每行的内容
"""
while True:
line = m_fr.readline()
if not line:
break
yield line
# 按行数拆分文件
# 将子文件存放到以文件名命名的文件夹中
def file_split_quick(m_filepath, m_num, m_dirpath, m_num_dict):
"""
按行分割大文件
:param m_filepath: 文件路径
:param m_num: 每个分割文件的行数
:param m_dirpath: 子文件存储目录
:param m_num_dict: 记录子文件行数的字典
"""
m_pathlist = []
if not os.path.exists(m_filepath):
print('error: not exist: {}'.format(m_filepath))
assert 0 == 1
if not os.path.exists(m_dirpath):
os.makedirs(m_dirpath)
m_filename = os.path.basename(m_filepath)
m_out = []
m_cmd = "wc -l {}".format(m_filepath)
execute_command(m_cmd, m_out)
m_total_num = int(m_out[0].split(' ')[0])
if m_total_num > m_num:
m_count = 0
with open(m_filepath, 'r', encoding='utf-8')
Python 高效分割大文件 按行数拆分大文件
于 2023-07-13 17:16:19 首次发布


1万+

被折叠的 条评论
为什么被折叠?



