title: Python: Open Excel Workbook If it Exists or Create it
body: <p>I am trying to get a good method to see if an Excel spreadsheet exists, if it does use that, if not create a new excel file.  See code snippet below.  The weird thing is every time I run it, it crashed on first attempt.  If I run it again, it cruises through.  Any ideas why?  I am thinking it has something to do with xlrd vs. xlwt, but haven't found a solution yet.  All modules are up-to-date.</p>
  
  <pre><code>import pandas as pd
  import xlsxwriter
  from xlrd import open_workbook
  import xlwt
  import os.path
  
  fname=r'testmonthlyz.xlsm'
  fname2=r'testmonthlyoutput2.xlsx'
  #workbook = xlsxwriter.Workbook(fname2)    
  if os.path.isfile(fname2):
      print('old file')
      book=open_workbook(fname2)
  else:
      print('new file')
      book=xlwt.Workbook(fname2)
      ws = book.add_sheet('Tested')
  sheet_names=book.sheet_names()
  </code></pre>