Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3947682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:16:52+00:00 2026-05-20T01:16:52+00:00

import time import traceback import sys import tools from BeautifulSoup import BeautifulSoup f =

  • 0
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()

It prints just fine. It just won’t write to the file. It’s 0 bytes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:16:52+00:00Added an answer on May 20, 2026 at 1:16 am

    You can never leave the while loop, hence the f.close() call will never be called and the stream buffer to the file will never be flushed.

    Let me explain a little bit further, in your exception catch statement you’ve included continue so there’s no “exit” to the loop condition. Perhaps you should add some sort of indicator that you’ve reached the end of the page instead of a static 1. Then you’d see the close call and information printed to the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If this is my subprocess: import time, sys for i in range(200): sys.stdout.write( 'reading
I've used the new installers from http://www.riverbankcomputing.co.uk/software/pyqt/download for Python 2.6 x86_64 and I've a
I try to run #!/usr/bin/env python import os from numpy import * b= ones((3,
import sys words = { 1 : 'one', 2 : 'two', 3 : 'three',
Are there any import and export tools that would let us move projects into
I have this problem. Any idea? from OpenGL.raw.GLUT import * File /usr/lib/python2.6/site-packages/OpenGL/raw/GLUT/__init__.py, line 6,
Running python on Snow Leopard, and I can't import the 'time' module. Works in
i am trying to import the content of my blog using BeautifulSoup,using the the
from celery.task import Task class Decayer(Task): def calc_decay_value(self, x): y = (1.0/(2^x)) return y
I am trying to run this snippet from http://www.ibm.com/developerworks/linux/library/l-prog3.html on a python 2.6 runtime.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.