Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # A couple of functions for opening web pages in the default
- # browser
- from webbrowser import open as webopen
- from webbrowser import open_new_tab
- # An operating system-specific function for getting the current
- # working directory (presumably the one in which this program
- # is running)
- from os import getcwd
- # An operating system-specific function for 'normalising' a
- # path to a file to the path naming conventions used on this
- # platform
- from os.path import normpath
- # The contents of a web document we want to create
- web_doc = "<html><body>Hello World</body></html>"
- # Create the document in a local file
- web_file = open('document.html', 'w')
- web_file.write(web_doc)
- web_file.close()
- # Create the full pathname to the file
- filename = getcwd() + '/document.html'
- # Normalise the path for the current OS
- filename = normpath(filename)
- # Open the document as a new tab in the default browser
- #
- # This version works for Mac OS X and Firefox:
- open_new_tab('file://' + filename)
- #
- # This version works for Microsoft Windows 7 and IE:
- # open_new_tab(filename)
- print 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement