I have to open multiple presentation using a loop, get some data and close it.
I cannot seem to find a way to close the ppt file in python pptx without saving/overwriting it.
I use the following to open the ppt file
pptfile = addressList[xyz]
prs = Presentation(pptfile)
slides = prs.slides
but I cannot find a way to close to presentation(prs) without saving in order to load the next ppt
I have a temporary work around which is as follows
prs.save(r"C:\Users\prashant.kumar\temp.pptx")
Since prs.save closes the ppt it works fine but I want a better way to close the ppt without creating a temp ppt file.
Is there an attribute of Presentation for python-pptx which I can use to close the ppt without saving?
python-pptx does not hold a file open while you are working on it. When you call:
prs = Presentation(pptfile)
The file pptfile is opened, read into memory, and closed, all before returning the Presentation object. So you can just use the prs reference for whatever you need and then abandon it for garbage collection, the same as any other object in Python.
You don't mention in your question a problem with some operation not being permitted because a file is open, so I assume you just thought that would be a problem and haven't actually encountered one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With