/
shaman_mir
/
partition_code_tree
Обзор
Документация
Войти
/
shaman_mir
/
partition_code_tree
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
partition_code_tree.py
34 строки
1 KB
Руслан Миронов
upload files
12 янв 2026, 07:28
12 янв 2026, 07:28
edf499e
Код
Авторство
О чём код?
import os def partition_file(input_file, output_prefix, part_size_mb): part_size_bytes = part_size_mb * 1024 * 1024 # 4.5 МБ в байтах with open(input_file, 'r', encoding='utf-8') as file: part_number = 1 current_part_size = 0 current_part_lines = [] for line in file: line_size = len(line.encode('utf-8')) if current_part_size + line_size > part_size_bytes: # Записываем текущую часть в файл with open(f"{output_prefix}_{part_number}.txt", 'w', encoding='utf-8') as output_file: output_file.writelines(current_part_lines) # Начинаем новую часть part_number += 1 current_part_size = 0 current_part_lines = [] current_part_lines.append(line) current_part_size += line_size # Записываем последнюю часть if current_part_lines: with open(f"{output_prefix}_{part_number}.txt", 'w', encoding='utf-8') as output_file: output_file.writelines(current_part_lines) if __name__ == "__main__": input_file = "Code_Tree.txt" output_prefix = "Code_Tree" part_size_mb = 4.5 partition_file(input_file, output_prefix, part_size_mb) print(f"Файл {input_file} успешно разделён на части по {part_size_mb} МБ.")