Advertisement
agough

Web Page Display_Mac_Windows

Jul 27th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # A couple of functions for opening web pages in the default
  2. # browser
  3. from webbrowser import open as webopen
  4. from webbrowser import open_new_tab
  5.  
  6. # An operating system-specific function for getting the current
  7. # working directory (presumably the one in which this program
  8. # is running)
  9. from os import getcwd
  10.  
  11. # An operating system-specific function for 'normalising' a
  12. # path to a file to the path naming conventions used on this
  13. # platform
  14. from os.path import normpath
  15.  
  16. # The contents of a web document we want to create
  17. web_doc = "<html><body>Hello World</body></html>"
  18.  
  19. # Create the document in a local file
  20. web_file = open('document.html', 'w')
  21. web_file.write(web_doc)
  22. web_file.close()
  23.  
  24. # Create the full pathname to the file
  25. filename = getcwd() + '/document.html'
  26.  
  27. # Normalise the path for the current OS
  28. filename = normpath(filename)
  29.  
  30. # Open the document as a new tab in the default browser
  31. #
  32. # This version works for Mac OS X and Firefox:
  33. open_new_tab('file://' + filename)
  34. #
  35. # This version works for Microsoft Windows 7 and IE:
  36. # open_new_tab(filename)
  37.  
  38. print 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement