title: Python: Pause for-loop while application closes
body: <p>I have a script that I would like to bulk edit powerpoint files with. If I edit files one by one with it, it works great. If I bulk edit them, it fails. I assume this is because the application is not closing before the next file attempts to load, but I could, and most likely am, wrong. </p>
  
  <p>The code:</p>
  
  <pre><code>import win32com.client, sys, glob
  
  
  folder = (glob.glob('*.ppt'))
  
  print("="*20)
  print(folder)
  print("="*20)
  
  if folder:
      for files in folder:
          print("Current File: " + files)
          try:
              Application = win32com.client.Dispatch("PowerPoint.Application")
              Application.Visible = True
              Presentation = Application.Presentations.Open("c:/pptpy/testfolder/" + files)
              for Slide in Presentation.Slides:
                  for Shape in Slide.Shapes:
                      try:
                          Shape.TextFrame.TextRange.Font.Name = "Arial"
                          Shape.TextFrame.TextRange.Font.Size = "14"
                          Shape.TextFrame.TextRange.Font.Color.RGB = "000000"
                      except:
                          pass
              Presentation.Save()
              Application.Quit()
                  #Adding a time.sleep(1) here pauses the Application.Quit()
          except:
              print("Error in: " + files)
              pass
  </code></pre>
  
  <p>The error (when not passing exceptions):</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\pptpy\testfolder\convert.py", line 19, in &lt;module&gt;
      for Shape in Slide.Shapes:
    File "C:\Python33\lib\site-packages\win32com\client\dynamic.py", line 247, in __getitem__
      return self._get_good_object_(self._enum_.__getitem__(index))
    File "C:\Python33\lib\site-packages\win32com\client\util.py", line 37, in __getitem__
      return self.__GetIndex(index)
    File "C:\Python33\lib\site-packages\win32com\client\util.py", line 53, in __GetIndex
      result = self._oleobj_.Next(1)
  pywintypes.com_error: (-2147023174, 'The RPC server is unavailable.', None, None)
  </code></pre>
  
  <p>Details:</p>
  
  <p>Python3.3</p>
  
  <p>Powerpoint2007</p>
  
  <p>If you need any more details, I would be happy to provide them!
  Thanks!</p>