1 Replies - 1278 Views - Last Post: 01 March 2011 - 05:56 AM Rate Topic: -----

#1 progCS45  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-February 11

Python file to print in web browser

Posted 28 February 2011 - 08:49 PM

I have a python file that I want to print out in a web browser. The web browser opens up but the information does not print to the page. Any help would be appreciated.
 
"""Prints CRN numbers"""
    testfile = open(file_name,'r')
    allrows = testfile.readlines()
    cols = [a.split(",")[crn_column] for a in allrows ]
    d={}
    for line in allrows:
        values=line.split(",")
        if(d.has_key(values[0])):
            d[values[0]].append(values[1])
        else:
            d[values[0]]=[values[1]]
    print (d.keys())
    file = open('insert.html','w')
    message = """<html> <head>hello</head><body>" "</body></html>"""
    file.writelines(message)
    webbrowser.open_new_tab('insert.html')



Is This A Good Question/Topic? 0
  • +

Replies To: Python file to print in web browser

#2 Eric115  Icon User is offline

  • coderさん
  • member icon

Reputation: 63
  • View blog
  • Posts: 697
  • Joined: 19-January 09

Re: Python file to print in web browser

Posted 01 March 2011 - 05:56 AM

Hi, I ran your code a few times and found that your problem was that you didn't close the file when you were done with it! Because of this, the web browser can't read from the file. Just add in file.close() on line 16 and it should all work!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1