0

i've tried with below code but i couldn't save PPT file as PPTX file.

from pptx import Presentation
import os
import glob

for each_file in glob.glob("C:/Users/Downloads/*.ppt"):
    #prs = Presentation(each_file)
    fname=os.path.basename(each_file)
    f = open(each_file)
    f.save(fname[:-4]+'.pptx')
    f.close()```


***Error***: `AttributeError: '_io.TextIOWrapper' object has no attribute 'save'`


1 Answers1

0

It looks like .ppt files are not supported.

The following line (.ppt files from PowerPoint 2003 and earlier won’t work) is on page 13 of the python-pptx docs: https://readthedocs.org/projects/python-pptx/downloads/pdf/latest/

David Erickson
  • 16,433
  • 2
  • 19
  • 35
  • David, I have come to know that `python-pptx` doesn't support `.ppt` files. but, how to read `.ppt` files in python? or how do i convert `.ppt` files to `.pptx` files? – shivakumar kasha Apr 04 '20 at 16:25
  • @shivakumarkasha I don't know of any Python library that reads the old binary format. You can open them one at a time in PowerPoint and save as PPTX: https://support.office.com/en-us/article/Convert-a-presentation-from-a-previous-PowerPoint-version-to-PowerPoint-2013-or-later-7d12fccd-5de9-4a5c-96ac-ec3483a4df67. Also there are online conversion utilities but you never know what they do with your content, so be circumspect about that possible route. – scanny Apr 04 '20 at 18:13
  • @scanny I'm able to convert a single `.ppt` file to `.pptx` but i need to convert multiple files at a time. i have tried conversion using python `os.rename()`. file extension is changing but unable to open the files. – shivakumar kasha Apr 05 '20 at 22:03
  • Changing the extension is not going to do it. The `.ppt` format is in an undocumented binary format whereas the `.pptx` format is XML-based. They need to be converted by conversion software built for that job. – scanny Apr 05 '20 at 22:25