【问题标题】:How to choose saving directory with python-pptx?如何使用 python-pptx 选择保存目录?
【发布时间】:2019-02-03 00:33:57
【问题描述】:

我对python很陌生,我一直在用pptx python做一个项目。 一切都很好,但我不明白如何选择我的文件将保存在哪个目录中。

这是我的代码:

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:我使用的是 python 3.7

【问题讨论】:

    标签: python directory save python-pptx


    【解决方案1】:

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

    prs.save('test.pptx') 是相对路径。因此 test.pptx 将与您的脚本存储在同一目录中。如果您想要另一个位置,请使用绝对路径,例如 prs.save('C:/Users/xyz/Desktop/data/test.pptx')

    This Link may be helpful too! ;)

    【讨论】:

    • 非常感谢。绝对路径是我需要的概念,因为我创建了一个 pptx 工厂,它必须将 pptx 保存在不同的文件夹中。
    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 2018-07-15
      • 2020-12-08
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多