
Here are the instructions for today’s final project:
Create a letter using starting_letter.txt for each name in invited_names.txt. Replace the [name] placeholder with the actual name. Save the letters in the folder "ReadyToSend".
#Hint1: This method will help you: https://www.w3schools.com/python/ref_file_readlines.asp #Hint2: This method will also help you: https://www.w3schools.com/python/ref_string_replace.asp #Hint3: This method will help you: https://www.w3schools.com/python/ref_string_strip.asp
So we need take the names from a file, append them to a list, and replace a placeholder in a letter we also import from a text file with each name in the list. Lets do it.
names_list = []
with open("./Input/Names/invited_names.txt") as names_file:
names = names_file.readlines()
for item in names:
str(f"{item}")
names_list.append(item)
for i in range(len(names_list)):
names_list[i] = names_list[i].strip()
with open("./Input/Letters/starting_letter.txt") as letter_file:
letter_from_file = letter_file.readlines()
letter_holder = str(letter_from_file)
for x in range(len(names_list)):
letter = letter_holder.replace("[name]", names_list[x])
with open(f"./Output/ReadyToSend/LetterTo{names_list[x]}.txt", mode="w") as txtfile:
txtfile.write(letter)