我创建了一个脚本,它从csv文件中读取信息并将其输出到docx文件。我的问题是,当docx文件保存时,它会将其保存到我的python脚本所在的同一文件夹中。我的桌面上有一个名为python的文件夹,在这个文件夹中是我要保存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
答案 0 :(得分:2)
如果它还没有传递完整路径,而不是只传递 <script type="text/javascript">
var settings = {
"async": true,
"crossDomain": true,
"url": "https://api.bigcommerce.com/stores/***/v3/catalog/products?include=variants%2Ccustom_fields",
"method": "GET",
"headers": {
"x-auth-client": "d8zpoak96***",
"x-auth-token": "i64oipln27l***",
"cache-control": "no-cache",
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
</script>
,而是修改filename
方法以获取完整的文件路径并传递它。
Document.save