如何使用pythonptx选择保存目录?

2024-05-28 19:48:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python很陌生,我一直在用pptxpython开发一个项目。 一切正常,但我不知道如何选择我的文件将保存在哪个目录。在

这是我的代码:

from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]

title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"

prs.save('test.pptx')

它会把文件保存在我的桌面上。如何选择目录?在

提前谢谢! PS:我使用的是Python3.7


Tags: 文件项目代码textfrom目录titlepresentation
2条回答
def save(self, path_or_stream):
    """
    Save this presentation package to *path_or_stream*, which can be
    either a path to a filesystem location (a string) or a file-like
    object. for example save(self, 'C:\mypath'):
    """
    self.package.save(path_or_stream)

让我猜猜-python脚本也在桌面上!在

prs.save('test.pptx')是相对路径。所以测试.pptx将存储在与脚本相同的目录中。如果需要其他位置,请使用绝对路径,如prs.save('C:/Users/xyz/Desktop/data/test.pptx')

This Link may be helpful too! ;)

相关问题 更多 >

    热门问题