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

Discussion in 'Python' started by Mitchell L Model, Jan 27, 2010.

  1. On Jan 27, 2010, at 3:31 PM, Timur Tabi wrote:

    > On Wed, Jan 27, 2010 at 12:29 PM, Mitchell L Model
    > <> 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.
    Mitchell L Model, Jan 27, 2010
    1. Advertisements

  2. Paul Boddie

    Paul Boddie Guest

    On 27 Jan, 23:00, Mitchell L Model <> 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.

    Paul Boddie, Jan 27, 2010
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robin
    May 18, 2006
  2. krishnakant Mane

    problem opening html file with

    krishnakant Mane, Oct 29, 2007, in forum: Python
    Stefan Behnel
    Oct 29, 2007
  3. krishnakant Mane
    krishnakant Mane
    Nov 12, 2007
  4. Replies:
    Arne Vajhøj
    Feb 10, 2008
  5. Timur Tabi
    Timur Tabi
    Jan 18, 2010

Share This Page