Advertisement
plarmi

workpython_14_3

Jul 9th, 2023
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def remove_last_line(file_path, output_file_path):
  2.     with open(file_path, 'r') as file:
  3.         lines = file.readlines()
  4.        
  5.     with open(output_file_path, 'w') as output_file:
  6.         output_file.writelines(lines[:-1])
  7.  
  8. # Пример использования
  9. input_file_path = 'input.txt'           # Путь к исходному файлу
  10. output_file_path = 'output.txt'         # Путь к файлу с результатом
  11.  
  12. remove_last_line(input_file_path, output_file_path)
  13.  
  14. print("Последняя строка удалена из файла и результат записан в другой файл.")
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement