开发者

printing to the screen on the same line at different times

开发者 https://www.devze.com 2022-12-27 16:23 出处:网络
My code looks like this: print \"Doing Something...\", do_some_function_that_takes_a_long_time() print \"Done\"

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?


You have to flush the output after your first print.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消