gpt4 book ai didi

python - 如何在控制台上的同一位置写入输出?

转载 作者:IT老高 更新时间:2023-10-28 12:29:10 29 4
gpt4 key购买 nike

我是python新手,正在编写一些脚本来自动从FTP服务器等下载文件。我想显示下载的进度,但我希望它保持在同一个位置,例如:

输出:

Downloading File FooFile.txt [47%]

我试图避免这样的事情:

     Downloading File FooFile.txt [47%]
Downloading File FooFile.txt [48%]
Downloading File FooFile.txt [49%]

我该怎么做呢?


重复:How can I print over the current line in a command line application?

最佳答案

也可以使用回车:

sys.stdout.write("Download progress: %d%%   \r" % (progress) )
sys.stdout.flush()

关于python - 如何在控制台上的同一位置写入输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/517127/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com