import os def trim_last_newline(file_path): with open(file_path, 'r+') as file: file.seek(0, os.SEEK_END) file.seek(file.tell() - 1, os.SEEK_SET) file.truncate() def process_pos_file(): with open('pos.txt', 'r') as file: data = file.read() data = data.replace('.jpg', '.jpg 1 0 0 20 20') with open('pos.txt', 'w') as file: file.write(data) if __name__ == "__main__": trim_last_newline('neg.txt') trim_last_newline('pos.txt') process_pos_file()