Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = "Dear NAME, it was nice to meet you on DATE. Hope to talk with you and SPOUSE again soon!"
- NAME, DATE, SPOUSE
- John, October 1, Jane
- Jane, September 30, John
- ...
- with open('recipients.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- for match in matchedfields:
- print inputtext.replace(match, row[match])
- "Dear John, it was nice to meet you on October 1. Hope to talk with you and Jane again soon!"
- "Dear Jane, it was nice to meet you on September 30. Hope to talk with you and John again soon!"
- import copy
- with open('recipients.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- inputtext_copy = copy.copy(inputtext) ## make a new copy of the input_text to be changed.
- for match in matchedfields:
- inputtext_copy = inputtext_copy.replace(match, row[match]) ## this saves the text with the right
- print inputtext ## should be the original w/ generic field names
- print inputtext_copy ## should be the new version with all field changed to specific instantiations
- import string
- templateText = string.Template("Dear ${NAME}, it was nice to meet you on ${DATE}. Hope to talk with you and ${SPOUSE} again soon!")
- import csv
- with open('recipients.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- print(templateText.safe_substitute(row))
- with open('recipients.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- inputtext = text
- for match in matchedfields:
- inputtext = inputtext.replace(match, row[match])
- print inputtext
- text = "Dear {0[NAME]}, it was nice to meet you on {0[DATE]}. Hope to talk with you and {0[SPOUSE]} again soon!"
- with open('recipients.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- for row in reader:
- inputtext = text.format(row)
- print inputtext
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement