title: Why won't my script write to a file?
body: <pre><code>import time
  import traceback
  import sys
  import tools
  from BeautifulSoup import BeautifulSoup
  
  f = open("randomwords.txt","w")
  while 1:
      try:
          page = tools.download("http://wordnik.com/random")
          soup = BeautifulSoup(page)
          si = soup.find("h1")
          w = si.string
          print w
          f.write(w)
          f.write("\n")
          time.sleep(3)
      except:
          traceback.print_exc()
          continue
  
  
  f.close()
  </code></pre>
  
  <p>It prints just fine. It just won't write to the file. It's 0 bytes.</p>