[英]IndentationError In Python while Adding Progress Bar
我试图在程序中放入进度条,但出现错误。 我不知道如何正确使用它,因此进度条将被打印出来。
import time
import sys
toolbar_width = 40
# setup toolbar
sys.stdout.write("[%s]" % (" " * toolbar_width))
sys.stdout.flush()
sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
for i in xrange(toolbar_width):
time.sleep(0.1) # do real work here
# update the bar
sys.stdout.write("-")
sys.stdout.flush()
sys.stdout.write("\n")
这是我得到的错误:
IndentationError: unindent does not match any outer indentation level
听起来像是缩进错误。 在脚本上运行python -tt
以验证您没有混合使用制表符和空格。
最佳做法是仅使用空格或制表符,而不要同时使用两者。 大多数项目,当然还有Python样式指南PEP-8都建议您仅使用空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.