1

I'm calling a simple little method that prints an initial statement and then a period every second. It's printing each new dot on a new line, however, and I want them all on one line, like this: 'Checking. . . . . .'

When I follow the print statements with a comma, or if I use sys.stdout.write(), the method hangs until the entire loop is complete, and then prints all at once.

Here's my code. Using python 2.4.3 - don't have a choice about that, I'm afraid.

class WaitTimer(object):

    def timer(self, time, countDown=0):
        if countDown == 0:
            print "\nChecking.",
        if countDown <= time:
            countDown += 1
            print ".",

            self.timer(time, countDown)

wait = WaitTimer()

wait.timer(5)
Brad Koch
  • 19,267
  • 19
  • 110
  • 137
Faentur
  • 25
  • 1
  • 4

1 Answers1

0

I think you might want to have a call to sys.stdout.flush(), when you want the data to be displayed. I don't think print "blah", will do a flush.

Owen
  • 1,726
  • 10
  • 15