Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 加载错觉。写在同一行上_Python_Python 3.x - Fatal编程技术网

Python 加载错觉。写在同一行上

Python 加载错觉。写在同一行上,python,python-3.x,Python,Python 3.x,我想做一个程序的一部分,它看起来像是在结果中加载。比如: Installing.... 单词不稳定后会出现更多的点。最后的结果是: Instaling.......... [DONE] 我试过这样的方法,但效果不理想。程序只是需要更多的时间来写一行,它一次写所有的东西 import time print("Installing...", end="") time.sleep(2) print(".", end="") time.sleep(2) print("

我想做一个程序的一部分,它看起来像是在结果中加载。比如:

Installing....  
单词不稳定后会出现更多的点。最后的结果是:

Instaling.......... [DONE]    
我试过这样的方法,但效果不理想。程序只是需要更多的时间来写一行,它一次写所有的东西

import time  
print("Installing...", end="")  
time.sleep(2)  
print(".", end="")  
time.sleep(2)  
print(".")   

那是因为直到最后,这条线才被冲到终端。您可以手动刷新它:

import sys   # <-

print("Installing...", end="")
sys.stdout.flush()   # <-
print("Installing...", end="", flush=True)