1
我創建了一個從csv文件讀取信息並將其輸出到docx文件的腳本。我的問題是,當docx文件保存時,它將其保存到我的python腳本所在的同一個文件夾中。我的桌面上有一個名爲python的文件夾,在這個文件夾中我想保存docx文件。下面是我應該發生的一段腳本。謝謝你的幫助!Python 3:如何將docx文件保存到特定目錄?
customer_list = r'C:\Users\path to csv file'
csv_file = read_emails(customer_list) #Function that turns csv into dictionary
for customer in csv_file:
word_template = r'C:\Users\path to word template'
document = Document(word_template)
customer_email = customer['email']
customer_contact = customer['contact']
document.add_paragraph(respond_by)
document.add_paragraph(date_sign)
terms = r'C:\Users\path to terms and conditions'
with open(terms,'r') as trms:
for line in trms:
document.add_paragraph(line)
filename = (customer_contact + '.docx')
document.save(filename) #Here I want to save to a different folder
這工作,謝謝! – CrookTiny