Launch file based on association

Fredrik Lundh fredrik at pythonware.com
Mon Jan 23 10:43:44 EST 2006


Chris Cioffi wrote:

> Q:  If I have a file called "spreadsheet.xls" how can I launch it in what
> ever program it is associated with?  I don't care if that program is Excel
> or OpenOffice Calc.  I just want to launch the file.

>>> import os
>>> help(os.startfile)
Help on built-in function startfile in module nt:

startfile(...)
    startfile(filepath) - Start a file with its associated application.

    This acts like double-clicking the file in Explorer, or giving the file
    name as an argument to the DOS "start" command:  the file is opened
    with whatever application (if any) its extension is associated.

    startfile returns as soon as the associated application is launched.
    There is no option to wait for the application to close, and no way
    to retrieve the application's exit status.

    The filepath is relative to the current directory.  If you want to use
    an absolute path, make sure the first character is not a slash ("/");
    the underlying Win32 ShellExecute function doesn't work if it is.

</F> 






More information about the Python-list mailing list