1

Possible Duplicate:
Is it possible to open up certain web addresses using the default internet browser with python?

I know OS X has an open command, where you can pass in a URL, and it'll open up the default browser and point it to the given domain.

But how would I go about doing this for other unix-based AND windows-based machines? Basically, I'd like to make a CLI (written in python), and have a cross-OS way of opening the browser from the terminal.

Community
  • 1
  • 1
Connor
  • 4,138
  • 8
  • 34
  • 51

3 Answers3

8

webbrowser

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
4

"Unix" doesn't; OS X does. Linux and *BSD, if they have the freedesktop.org stuff installed, should have xdg-open (and if you're lucky it will even do something sensible); Windows has start (as in, start http://some.url should work). There are better ways to do this portably.

geekosaur
  • 59,309
  • 11
  • 123
  • 114
  • Thanks for the clarification - I just assumed it was for all unix-based machines, not just OS X. – Connor Apr 16 '12 at 02:49
0
import os

if os.name == 'posix':
    os.system("open "+str(website))
elif os.name == 'nt':
    os.system("start "+str(website))
Red_M
  • 75
  • 1
  • 2