How can I launch an instance of an application using Python?

后端 未结 7 1422
北恋
北恋 2020-12-09 04:57

I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that i

7条回答
  •  無奈伤痛
    2020-12-09 05:38

    While the Popen answers are reasonable for the general case, I would recommend win32api for this specific case, if you want to do something useful with it:

    It goes something like this:

    from win32com.client import Dispatch
    xl = Dispatch('Excel.Application')
    wb = xl.Workbooks.Open('C:\\Documents and Settings\\GradeBook.xls')
    xl.Visible = True    # optional: if you want to see the spreadsheet
    

    Taken from a mailing list post but there are plenty of examples around.

提交回复
热议问题