1
私はcsvファイルから情報を読み込んでdocxファイルに出力するスクリプトを作成しました。私の問題は、docxファイルが保存されると、私のpythonスクリプトが置かれているのと同じフォルダに保存されるということです。デスクトップ上にpythonと呼ばれるフォルダがあります。このフォルダ内にdocxファイルを保存する場所があります。以下は、これが行われるはずのスクリプトです。ご協力いただきありがとうございます!むしろ、それはすでに、完全なパスを取る完全なファイルパスを取るためにDocument.save
法を改正し、代わりにそれを渡していない場合は、ちょうどfilename
を渡すよりも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