我正在尝试编写一个程序,该程序向每个收件人和每个地址写入相同的字母,但每个字母将具有不同的名称和地址。
这就是我到目前为止所拥有的。
def main():
recipients = [] #should be names
adresses = [] #letters and numbers
filename = input("Please enter the name of the template file: ")
file = open(filename, 'w')
recipients = input("Please enter names of recipients: ")
adresses = input("Please list addresses: ")
for names in recipients:
letter = "New York, New York\n17 November 2013\n \n", recipients[names], "\n" ,adresses, "\n\nDear",recipients[names],"\n\n" \
"Thank you for your service to New York City, and\nin particular, to the education of its residents.\nThose in", adresses, "appreciate it!"\
"\n\nBest wishes to", recipients[names], "and your family,\n\n"
file.write(str(letter))
file.close()
main()
当它写出文件时,它只写一个字母并将所有内容放在一起。
我想要做的是写一封信给不同的人和同一个文件中的不同地址。
前任。这都将在同一个文件中。
New York, New York
11 March 2013
person1
Bronx NY
Dear person1,
Thank you for your service to New York City, and,
in particular, to the education of its residents.
Those in Bronx NY appreciate it!
Best wishes to person1 and your family
New York, New York
11 March 2013
Person2
New York NY
Dear person2,
Thank you for your service to New York City, and,
in particular, to the education of its residents.
Those in New York NY appreciate it!
Best wishes to person2 and your family
有什么帮助吗?
使用 Python 3.x
提前致谢