[英]Python - Rename file name in file attached
I have a Python script that sends a file attached in a mail. 我有一个Python脚本,用于发送邮件中附加的文件。 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. 下面给出的是我要作为附件发送的csv文件。 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. 我只想显示file.csv。
I tried using os
module but it returned an error path does not exist. 我尝试使用os
模块,但返回的错误路径不存在。
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.