writefile

Check if a string matches any of the lines of a txt file, and if it doesn't match any then add it to that txt file

Check if a string matches any of the lines of a txt file, and if it doesn't match any then add it to that txt file Question: import os if (os.path.isfile(‘data_file.txt’)): data_memory_file_path = ‘data_file.txt’ else: open(‘data_file.txt’, "w").close() data_memory_file_path = ‘data_file.txt’ #Example input list with info in sublists reordered_input_info_lists = [ [[‘corre’], [‘en el patio’], [‘2023-02-05 …

Total answers: 1

How to edit lines of a text file based on regex conditions?

How to edit lines of a text file based on regex conditions? Question: import re re_for_identificate_1 = r"" with open("data_path/filename_1.txt","r+") as file: for line in file: #replace with a substring adding a space in the middle line = re.sub(re_for_identificate_1, " milesimo", line) #replace in txt with the fixed line Example filename_1.txt : unmilesimo primero 1001° …

Total answers: 1