Reputation: 7994
I'm writing a python script that generates html file. Every time I run this script I'd like at the end to open default system browser for this file. It's all in OS X environment.
What python code can launch Safari/Firefox/whatever is system default html viewer and open given file? subprocess.call
doesn't seem to do the trick.
Upvotes: 2
Views: 593
Reputation: 114943
What python code can launch Safari/Firefox/whatever is system default html viewer and open given file?
There is a webbrowser module in python, try this:
import webbrowser
webbrowser.open('file://%s' % path)
This will open a new tab in the default browser. There are methods to open a new tab, new window and other options.
Upvotes: 3
Reputation: 80276
Do you know about the open
command in Mac OS X? I think you can solve your problem by calling it from Python.
man open
for details:
The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.
Upvotes: 1