I really need webbrowser.open('file://') to open a web browser
Mitchell L Model
MLMDev at Comcast.net
Wed Jan 27 13:29:41 EST 2010
On Jan 15, 2010, at 3:59 PM, Timur Tabi <timur at freescale.com>
> After reading several web pages and mailing list threads, I've learned
> that the webbrowser module does not really support opening local
> files, even if I use a file:// URL designator. In most cases,
> webbrowser.open() will indeed open the default web browser, but with
> Python 2.6 on my Fedora 10 system, it opens a text editor instead. On
> Python 2.5, it opens the default web browser.
>
> This is a problem because my Python script creates a local HTML file
> and I want it displayed on the web browser.
>
> So is there any way to force webbrowser.open() to always use an actual
> web browser?
I had some discussions with the Python documentation writers that led
to the following note being included in the Python 3.1 library
documentation for webbrowser.open: "Note that on some platforms,
trying to open a filename using this function, may work and start the
operating system’s associated program. However, this is neither
supported nor portable." The discussions suggested that this lack of
support and portability was actually always the case and that the
webbrowser module is simply not meant to handle file URLs. I had taken
advantage of the accidental functionality to generate HTML reports and
open them, as well as to open specific documentation pages from within
a program.
You can control which browser opens the URL by using webbrowser.get to
obtain a controller for a particular browser, specified by its
argument, then call the open method on the controller instead of the
module.
For opening files reliability and the ability to pick a particular
program (browser or otherwise) to open it with you might have to
resort to invoking a command line via subprocess.Popen.
More information about the Python-list
mailing list