Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: I really need'file://') to open a web browser

Thread Tools

Re: I really need'file://') to open a web browser

Mitchell L Model
Posts: n/a
On Jan 27, 2010, at 3:31 PM, Timur Tabi wrote:

> On Wed, Jan 27, 2010 at 12:29 PM, Mitchell L Model
> <(E-Mail Removed)> wrote:
>> 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
>> "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."

> Then they should have renamed the API. I appreciate that they're
> finally documenting this, but I still think it's a bunch of baloney.

I agree, but I am pretty sure that, based on the discussions I had
with the Python
documenters and developers, that there's no hope of winning this
I suppose that since a file: URL is not, strictly speaking, on the
web, that it
shouldn't be opened with a "web" browser. It's just that the "web"
part of
"web browser" became more or less obsolete a long time ago since there
are so many more ways of using browsers and so many more things they can
do then just browse the web. So if you interpret the name "webbrowser"
to mean
that it browses the web, as opposed to files, which means going
through some
kind of server-based protocol, the module does what it says. But I
still like
the idea of using it to open files, especially when I want the file to
be opened
by its associated application and not a browser.

>> 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.

> How can I know which controller (application) the system will use when
> it opens an http URL? I depend on'http') to choose
> the best web browser on the installed system. Does webbrowser.get()
> tell me which application that will be?

webbrowser.get() with no arguments gives you the default kind of
browser controller, just as if you had used

>> 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.

> But that only works if I know which application to open.

Aha. You could use subprocess to specify the application from within
your Python code,
but not to indicate "the user's default browser", unless the platform
has a command for that.
On OS X, for instance, the command line:
open file.html
opens file.html with the application the user has associated with html
files, whereas
open -a safari file.html
will open it with Safari even if the user has chosen Firefox for html
files. There's
stuff like this for Windows, I suppose, but hardly as convenient. And
I think that
Linux environments are all over the place on this, but I'm not sure.

webbrowser.get() returns a control object of the default class for the
user's environment --
the one that means "use the default browser" so it won't help.
Reply With Quote
Paul Boddie
Posts: n/a
On 27 Jan, 23:00, Mitchell L Model <(E-Mail Removed)> wrote:
> I suppose that since a file: URL is not, strictly speaking, on the *
> web, that it shouldn't be opened with a "web" browser.

But anything with a URL is (or should be regarded as being) on the
Web. It may not be anything more than a local resource and thus have
no universal or common meaning - someone else may not be able to
resolve the URL to a file at all, or it may resolve to a different
file - but it's part of the Web as observed by one party.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I really need'file://') to open a web browser Timur Tabi Python 4 01-18-2010 09:00 PM
I really need help with this so if anyone can help me out that wouldbe really great of you. Java 30 02-10-2008 11:29 PM
Open .msg / .eml file in Browser/placeholder within browser ai4u ASP .Net 0 04-27-2006 11:29 AM
do we really-really need Photoshop Elements? Giovanni Azua Digital Photography 6 05-18-2005 04:22 PM
REALLY REALLY WERID PROBLEM!!!!pls take a look Amir ASP .Net 3 01-23-2004 06:01 PM