I have this code that takes a list of name from a file, gets a letter example for another file an then creates personal letter with the names, the thing is my code creates empty letters for some reason, even dou is the same, the funny thing is, if i run the answer code it does the job perfectly
i copied the code format from the answer code and it keeps making empty letters, i am using pycharm
MY CODE
PLACEHOLDER = "[name]"
with open("./Input/Names/invited_names.txt") as names_file:
names = names_file.readlines()
with open("./Input/Letters/starting_letters.txt") as letters_file:
letter_content = letters_file.read()
for name in names:
strip_name = name.strip()
new_letter = letter_content.replace(PLACEHOLDER, strip_name)
with open(f"./Output/ReadyToSend/Letter_for_{strip_name}.txt", mode="w") as completed_letter:
completed_letter.write(new_letter)
ANSWER CODE
PLACEHOLDER = "[name]"
with open("./Input/Names/invited_names.txt") as names_file:
names = names_file.readlines()
with open("./Input/Letters/starting_letter.txt") as letter_file:
letter_contents = letter_file.read()
for name in names:
stripped_name = name.strip()
new_letter = letter_contents.replace(PLACEHOLDER, stripped_name)
with open(f"./Output/ReadyToSend/letter_for_{stripped_name}.txt", mode="w") as completed_letter:
completed_letter.write(new_letter)