6

My code looks like this:

print "Doing Something...",
do_some_function_that_takes_a_long_time()
print "Done"

I want it to print that statement at the top to the screen first, then do the function, and then print the "Done" line. Currently it waits until the "Done" line is executed before it prints the top part with it.

In other words, I want the pausing to occur with "Doing Something..." on the screen. How do I achieve this?

priestc
  • 33,060
  • 24
  • 83
  • 117

2 Answers2

9

You have to flush the output after your first print.

Community
  • 1
  • 1
vladr
  • 65,483
  • 18
  • 129
  • 130
0

You can also do something like: http://www.mutaku.com/wp/index.php/2011/06/python-dynamically-printing-to-single-line-of-stdout/

Matthew
  • 737
  • 10
  • 15