python-pptx如何选择保存目录?
How to choose saving directory with python-pptx?
我是 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 脚本也在桌面上!
prs.save('test.pptx')
是相对路径。因此 test.pptx 将存储在与您的脚本相同的目录中。如果您想要其他位置,请使用绝对路径,例如 prs.save('C:/Users/xyz/Desktop/data/test.pptx')
This Link may be helpful too! ;)
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 的新手,我一直在使用 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 脚本也在桌面上!
prs.save('test.pptx')
是相对路径。因此 test.pptx 将存储在与您的脚本相同的目录中。如果您想要其他位置,请使用绝对路径,例如 prs.save('C:/Users/xyz/Desktop/data/test.pptx')
This Link may be helpful too! ;)
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)