如何编写带有路径连接的变量名的输出文件



我想保存文件名,我的文件名应该是这样的"doc00012dsadfile5.jpg">


filename = "doc00012dsad.pdf"
mypath = "/desktop/myfolder/"
_path = os.path.join(mypath,"images")
num = 5
#filename.split(".pdf",1)[0] 
os.path.join(_path, file%d.jpg" % num), xx)       
filename = "doc00012dsad.pdf"
mypath = "/desktop/myfolder/"
_path = os.path.join(mypath,"images")
num = 5
#filename.split(".pdf",1)[0] 
os.path.join(_path, "file{}.jpg".format(num), xx)

我不知道xx是什么,但我只是把它放在那里,因为它在你的代码中

在加入前注入,避免混淆

import os
filename = "doc00012dsad.pdf"
mypath = "/desktop/myfolder/"
_path = os.path.join(mypath,"images")
num = 5
file ="file"
f_name = os.path.splitext(filename)[0]
filename = f'{f_name}{file}{num}.jpg'
final = os.path.join(_path,filename)

最终路径

/desktop/myfolder/images/doc00012dsadfile5.jpg

相关内容

  • 没有找到相关文章

最新更新