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

Cut7er
  • 1,209
  • 9
  • 24
Alex Daxe
  • 49
  • 6

2 Answers2

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

Cut7er
  • 1,209
  • 9
  • 24
  • 1
    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. – Alex Daxe Aug 28 '18 at 11:58
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)
Papershine
  • 4,995
  • 2
  • 24
  • 48