Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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_Macos_Terminal_Progress Bar - Fatal编程技术网

Python 如何在终端中打印进度条?

Python 如何在终端中打印进度条?,python,macos,terminal,progress-bar,Python,Macos,Terminal,Progress Bar,当homebrew下载软件时,有一个进度条,非常好 ######################################################################## 100.0% 我编写了一些Python脚本,并在终端中运行它们,我希望有与脚本运行相同的进度条。例如,如果我有一个长的For循环,我希望这个进度条在循环中运行。如何用Python打印此进度条?您需要类似的东西 import sys import time for n in xrange(100):

当homebrew下载软件时,有一个进度条,非常好

######################################################################## 100.0%

我编写了一些Python脚本,并在终端中运行它们,我希望有与脚本运行相同的进度条。例如,如果我有一个长的
For
循环,我希望这个进度条在循环中运行。如何用Python打印此进度条?

您需要类似的东西

import sys
import time

for n in xrange(100):
    time.sleep(1)
    sys.stdout.write("#")
    sys.stdout.flush()

您只需写出一个“#”,然后刷新tty,也就是要求控制台从
stdout
中提取并更新

这是一个复杂的问题。。请注意,这是我自己写的。谢谢你指出副本。但这并不是OP想要的!