The Personalized Letter Generator is a Python script that automates the process of generating personalized letters for multiple recipients. It reads a list of names from a file, replaces a placeholder in a letter template with each name, and creates individualized letters for each recipient.
-
Input Files:
Names_container.txt: Contains a list of names, with each name on a separate line.Letter_container.txt: Contains the letter template with a placeholder[NAME]where the recipient's name will be inserted.
-
Processing:
- The script reads the list of names from
Names_container.txt. - It reads the letter template from
Letter_container.txt. - For each name in the list, it replaces the placeholder
[NAME]in the letter template with the actual name. - It creates a new text file for each recipient with the personalized letter.
- The script reads the list of names from
-
Output:
- Individualized letters are saved in the
Outputdirectory with filenames formatted asletter_for_[NAME].txt.
- Individualized letters are saved in the
-
Prepare Input Files:
- Ensure that
Names_container.txtcontains the list of names andLetter_container.txtcontains the letter template with[NAME]as a placeholder.
- Ensure that
-
Run the Script:
- Execute the Python script
main.py.
- Execute the Python script
-
Generated Letters:
- Personalized letters for each recipient will be created and saved in the
Outputdirectory.
- Personalized letters for each recipient will be created and saved in the
- Python 3.x
The readlines() method reads all lines from the file and returns them as a list of strings.
with open("example.txt", "r") as file:
lines = file.readlines()
print(lines)The strip() method removes leading and trailing whitespace (including newline characters) from a string.
line = " Hi ! I am Himel \n"
stripped_line = line.strip()
print(stripped_line) # Output: "Hi ! I am Himel"The replace() method replaces occurrences of a specified substring with another string.
text = "Hello, [NAME]! How are you, [NAME]?"
new_text = text.replace("[NAME]", "Himel")
print(new_text) # Output: "Hello, Himel! How are you, Himel?"# Read lines from a file, strip whitespace, and replace placeholders
with open("example.txt", "r") as file:
lines = file.readlines()
for line in lines:
stripped_line = line.strip() # Strip leading/trailing whitespace
replaced_line = stripped_line.replace("[NAME]", "Himel") # Replace placeholders
print(replaced_line)This example reads lines from a file, strips whitespace, and replaces placeholders ([NAME]) with a specific name ("Himel").
Contributions to the Personalized Letter Generator are welcome! If you have any suggestions, bug fixes, or improvements, feel free to open an issue or submit a pull request.
Coded by -
- Himel Sarder
- Dept. of CSE, BSFMSTU, Bangladesh
- gmail : info.himelcse@gmail.com
This project is licensed under the MIT License. See the LICENSE file for details.
