[英]How to print a text progress bar when some text was in front of it in python 3?
好吧,我的意思是,这是我的代码:
def progress():
for i in range(100):
print('{0}\b\b'.format(i), end='', flush=True)
time.sleep(0.1)
print('progress bar test: {0} finished!'.format(progress()))
我想要这样的输出:
progress bar test: 1.2.3..(and then print 'finished!')
但是我得到了这个:
1.2.3...
progress bar test: None finished!
这是问题。 而且我也想知道如果数字小于10, \\b\\b
删除前面的文字吗?
您的函数没有返回值,因此您会看到默认情况下返回的None
。 循环完成"finished"
您可以返回"finished"
:
import time
def progress():
for i in range(3):
print('{0}.'.format(i), end='', flush=True)
time.sleep(0.1)
return "finished!"
print('progress bar test: {0}'.format(progress()))
如果您希望能够更改返回值,只需传入一个 arg:
def progress(end):
for i in range(3):
print('{0}.'.format(i), end='', flush=True)
time.sleep(0.1)
return end
print('progress bar test: {0} '.format(progress("finished!")))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.