python at deborahswanson.net
Wed Jan 4 03:19:32 EST 2017
Chris Angelico wrote, on January 04, 2017 4:16 AM
> Yeah, there's no simple answer; however, you'll find that
> Python on many platforms is entirely capable of popping a URL
> up in the user's default browser. Check this out:
> >>> import antigravity
I downloaded the code from the Package Index, but there really wasn't much in
it. This is the entire .py file:
STRIP_URL = "http://xkcd.com/353/"
And setup.py is equally disappointing: from distutils.core import setup
description='A really simple module that allow everyone to do
author_email='antigravity at x-phuture.com',
> This uses the 'webbrowser' module, which knows about a number
> of different ways to open a browser, and will attempt them
> all. So if you can figure out the UI part of things, actually
> making the link pop up in a browser isn't too hard; for
> instance, if you're doing OAuth at the command line and need
> the user to go and authenticate, you can simply
> webbrowser.open("http://......./") and it'll DTRT.
All the action of antigravity must be done by the import statement. When import
opens a module that immediately returns a url, it must have a mechanism to open
it in a browser.
It would be very easy to do the same thing with my own .py and import it into
Or, take a look at import's code and figure out how it opens a url in a
browser. I imagine it's the 'webbrowser' module you mention. If it tries
several methods, just pick one that will work for you.
Or, take a look at this Index of Packages Matching 'webbrowser' (~50 packages)
D'Arcy was right, there's lots in python that's internet aware, though that
wasn't the question I knew to ask.
More information about the Python-list