'''A simple program to create an html file froma given string, and call the default web browser to display the file.''' contents = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Hello</title> </head> <body> Hello, World! </body> </html> ''' def main(): browseLocal(contents) def strToFile(text, filename): """Write a file with the given name and the given text.""" output = open(filename,"w") output.write(text) output.close() 'def browseLocal(webpageText, filename='tempBrowseLocal.html'): def browseLocal(webpageText): '''Start your webbrowser on a local file containing the text with given filename.''' import webbrowser, os.path ' strToFile(webpageText, filename) ' webbrowser.open("file:///" + os.path.abspath(filename)) #elaborated for Mac webbrowser.open(webpageText) main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question