简体   繁体   中英

print statement delays printing when followed by comma

In Python 2.7, if I use print statement followed by comma as the following:

print('Generation ...'),
X, y = generate_dataset(num_samples)
print('Done!')

The first print print('Generation ...'), will NOT show up in the terminal until X, y = generate_dataset(num_samples) is finished! How can I force the print to immediately step by step with the existence of comma?

import sys

print "I'm going to do something that takes a long time...",
sys.stdout.flush()
really_time_consuming_function()
print "done!"

如果您不想在代码中处理它,也可以使用-u标志运行python解释器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM