I have a Python script that sends a file attached in a mail. The mail is sent however the attachment still displays the file path of my local system. Is there any way I could rename this path that is displayed in the mail attachment.
Given below is the csv file I am trying to send as an attachment. How could I rename the path shown in the attachment to only display the file name and not include the entire path
attach.to_csv('/Users/user/desktop/report/file.csv')
I would like to display just file.csv.
I tried using os
module but it returned an error path does not exist.
os.rename('/Users/user/desktop/report/file.csv','file.csv')
Try changing the dir and then attaching the file.
Ex:
import os
os.chdir('/Users/user/desktop/report')
attach.to_csv('file.csv')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.