/
chaoswork612
/
ReadFilesFromDirProject
Обзор
Документация
Войти
/
chaoswork612
/
ReadFilesFromDirProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
main.py
27 строк
680 B
Константин Морозов
Added Read Files From Dir Logic
26 мар 2025, 23:41
26 мар 2025, 23:41
8dd0a86
Код
Авторство
О чём код?
path = 'exercise3/' def read_stripped(file_path): with open(file_path) as file: yield file.name yield len(file.readlines()) with open(file_path) as f_file: for line in f_file: yield line.strip() def sort_files_list(file_names): files = [] for f in file_names: files.append(list(read_stripped(path + f))) return sorted(files, key=len) def write_file(file_path, mode): sorted_files = sort_files_list(['1.txt', '2.txt', '3.txt']) for f in sorted_files: with open(file_path, mode) as file: file.writelines("%s\n" % item for item in f) write_file(path + 'result.txt', 'a')