Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 in my script?

like image 603
Ray Avatar asked Oct 29 '08 17:10

Ray


People also ask

How do I open a file with a specific app in Python?

Opening files To open a file using the Python OS module, you need to import the OS module, then call the system() method and pass it the path of your file. It's important to recognize that the system() command doesn't open a file behind the scenes for reading or writing (file I/O).


1 Answers

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.

like image 66
Ali Afshar Avatar answered Sep 21 '22 16:09

Ali Afshar