Advertisement
plarmi

workpython_14_9

Jul 9th, 2023 (edited)
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. def combine_files(input_files, output_file):
  2.     with open(output_file, 'w') as output:
  3.         for file_name in input_files:
  4.             with open(file_name, 'r') as input_file:
  5.                 output.write(input_file.read())
  6.  
  7. # Пример использования
  8. input_files = []
  9. while True:
  10.     file_name = input("Введите название файла (или 'quit' для завершения): ")
  11.     if file_name == 'quit':
  12.         break
  13.     input_files.append(file_name)
  14.  
  15. output_file = 'combined_file.txt'  # Имя файла, в который будет объединено содержимое
  16. combine_files(input_files, output_file)
  17.  
  18. print(f"Содержимое файлов успешно объединено в файл '{output_file}'.")
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement