3

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 2

3

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! ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. The absolute path is the notion I needed as I made a pptx factory which has to save pptx in differents folders.
1
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) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.