import os
word_to_replace, replacement_word = "", ""
if (os.path.isfile('data_association/names.txt')):
word_file_path = 'data_association/names.txt'
else:
open('data_association/names.txt', "w")
word_file_path = 'data_association/names.txt'
word = "Claudio"
with open(word_file_path) as f:
lineas = [linea.strip() for linea in f.readlines()]
numero = None
if word in lineas: numero = lineas.index(word)+1
if numero != None:
#Here you must remove the line with the name of that file
else: print(That person's name could not be found within the file, so no line has been removed)
I need to try to remove that name from the following .txt file (assuming that there is a line with that name in that file, if it is a file without that line it should print that that name has not been found and that it cannot be deleted)
Lucy
Samuel
María del Pilar
Claudia
Claudio
Katherine
Maríne
After removing the line with the example name "Claudio"
, the file would look like this:
Lucy
Samuel
María del Pilar
Claudia
Katherine
Maríne
PS: this list of names is a reduced fragment of the actual list, so it's better if instead of rewriting the whole file, you just edit the specific line where that name was found