How to choose saving directory with python-pptx?

Viewed 1702

I'm pretty new to python and I've been working on a project with pptx python. Everything is fine, but I don't understand how to choose in which directory my file will be saved.

Here is my code:

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')

It will save the document on my desktop. How can I choose the directory ?

Thanks in advance! PS : I'm using python 3.7

2 Answers

Let me guess - the python script is on the Desktop too!

prs.save('test.pptx') is a relative path. So test.pptx will be stored in the same directory as your script. If you want another location, use an absolute path, like 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)
Related