Remove spaces at the beginning and at the end of the string:
txt = " banana "
x = txt.strip()
print("of all fruits", x, "is my favorite")
Replace the word "bananas":
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)
Return all lines in the file, as a list where each line is an item in the list object:
f = open("demofile.txt", "r")
print(f.readlines())
#TODO: 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>
with open("Input/Names/invited_names.txt") as name:
name_list = name.readlines()
print(name_list)
with open("Input/Letters/starting_letter.txt") as letter:
content = letter.read()
for invitee in name_list:
name = invitee.strip()
new_content = content.replace("[name]", name)
with open(f"letter for {name}.txt", mode="w") as invitation:
invitation.write(new_content)