sco*_*ttm 148 python console-output
我是python的新手,我正在编写一些脚本来自动从FTP服务器等下载文件.我想显示下载的进度,但我希望它保持在相同的位置,例如:
输出:
正在下载文件FooFile.txt [47%]
我试图避免这样的事情:
Downloading File FooFile.txt [47%]
Downloading File FooFile.txt [48%]
Downloading File FooFile.txt [49%]
Run Code Online (Sandbox Code Playgroud)
我应该怎么做呢?
cod*_*gic 239
您还可以使用回车:
sys.stdout.write("Download progress: %d%% \r" % (progress) )
sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)
RSa*_*bet 26
我喜欢以下内容:
print 'Downloading File FooFile.txt [%d%%]\r'%i,
Run Code Online (Sandbox Code Playgroud)
演示:
import time
for i in range(100):
time.sleep(0.1)
print 'Downloading File FooFile.txt [%d%%]\r'%i,
Run Code Online (Sandbox Code Playgroud)
print('Downloading File FooFile.txt [%d%%]\r'%i, end="")
Run Code Online (Sandbox Code Playgroud)
演示:
import time
for i in range(100):
time.sleep(0.1)
print('Downloading File FooFile.txt [%d%%]\r'%i, end="")
Run Code Online (Sandbox Code Playgroud)
Zac*_*ena 15
\b
多次打印退格符,然后用新号码覆盖旧号码.
小智 8
#kinda like the one above but better :P
from __future__ import print_function
from time import sleep
for i in range(101):
str1="Downloading File FooFile.txt [{}%]".format(i)
back="\b"*len(str1)
print(str1, end="")
sleep(0.1)
print(back, end="")
Run Code Online (Sandbox Code Playgroud)
对于Python 3xx:
import time
for i in range(10):
time.sleep(0.2)
print ("\r Loading... {}".format(i)+str(i), end="")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
164022 次 |
最近记录: |