[Tutor] Any easy way to invoke the default browser on a specified URL?

jfouhy@paradise.net.nz jfouhy at paradise.net.nz
Tue May 10 02:50:28 CEST 2005


Quoting Terry Carroll <carroll at tjc.com>:

> Is there any way, from within Python, to cause the default browser 
> (Firefox, in my case) to be invoked with a specific URL?

If you're on Win32, try:

>>> import win32api
>>> win32api.ShellExecute(0, 'open', 'http://www.google.com/', None, '', 1)

Parameters in order: 
 - Handle to the parent window (0 for no parent)
 - Operation to perform (you can also use 'print', and maybe others?)
 - Name of the file/shortcut to execute
 - Optional parameters for the new process
 - Initial directory for the new process
 - Flag indicating if the new window should be shown or not.

[information from Mark Hammond's book]

Basically, this does the same thing as double-clicking on the file/shortcut in
Windows Explorer.

If you're on Linux, I'm not sure.  I think different distros / window managers
may have different ways of defining things like a default browser, or different
ways of getting at them.

And I don't know anything about Mac OS X :-)

-- 
John.


More information about the Tutor mailing list