Welcome, guest | Sign In | My Account | Store | Cart
import BaseHTTPServer
import webbrowser

def LoadInDefaultBrowser(html):
    """Display html in the default web browser without creating a temp file.

    Instantiates a trivial http server and calls webbrowser.open with a URL
    to retrieve html from that server.

    class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
        def do_GET(self):
            bufferSize = 1024*1024
            for i in xrange(0, len(html), bufferSize):

    server = BaseHTTPServer.HTTPServer(('', 0), RequestHandler)
    webbrowser.open('' % server.server_port)

if __name__ == '__main__':
    LoadInDefaultBrowser('<b>Hello World</b>')


  • revision 3 (19 years ago)
  • previous revisions are not available