pythondirectorysavepython-pptx

How to choose saving directory with python-pptx?


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


Solution

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