Advertisement
Jexal

8c488b9a-9170-4ec0-8aa1-effae174bd26

Jan 21st, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. def remove_trailing_empty_line(file_path):
  2.     """
  3.    Removes any trailing empty line at the end of the file.
  4.    
  5.    :param file_path: Path to the file to be processed
  6.    """
  7.     # Read the file and remove trailing newline characters
  8.     with open(file_path, "r") as file_input:
  9.         file_data = file_input.read().rstrip('\n')
  10.    
  11.     # Write the processed data back to the file
  12.     with open(file_path, "w") as file_output:
  13.         file_output.write(file_data)
  14.  
  15. # Example usage of the function
  16. remove_trailing_empty_line(r"C:\Scripts\Archive.ph Link Saver\Resources\Data\Newly Modified URLs.txt")
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement