简体   繁体   English

预期if语句上的缩进块

[英]Expected an indented block on an if statement

# Check for log request
if len(sys.argv) >= 3:
    if sys.argv[3].lower() == 'log':
        logFiles = True

I haven't done Python for a while but I don't see anything wrong with the above code and it's saying that after the 'logFiles' before the = True is the problem. 我已经有一段时间没有使用Python了,但是我没有看到上面的代码有什么问题,这就是说在'logFiles'之后= = True是问题所在。

Ideas? 想法?

Python 2 treats a tab the same way Notepad does - as enough spaces to reach the next 8-space indentation level. Python 2对待制表符的方式与记事本相同-足够的空间可以达到下一个8位缩进级别。 This means if you mix tabs and spaces, you might see code that looks perfectly well indented, but Python sees a garbled mess. 这意味着如果混合使用制表符和空格,则可能会看到缩进的代码,但Python会看到乱码。 (In Python 3, Python will give you a helpful TabError: inconsistent use of tabs and spaces in indentation if it sees that you're mixing tabs and spaces.) Your code has a tab on the second line and 4 spaces and a tab on the second. (在Python 3中,Python将为您提供一个有用的TabError: inconsistent use of tabs and spaces in indentation如果TabError: inconsistent use of tabs and spaces in indentation如果它发现您混用了制表TabError: inconsistent use of tabs and spaces in indentationTabError: inconsistent use of tabs and spaces in indentation 。)您的代码在第二行有一个制表符,在第4行有一个制表符,在第二。 This looks like 1 indent, then 2, but Python doesn't see it that way. 看起来像是1个缩进,然后是2个缩进,但是Python并没有那样看。

Don't mix tabs and spaces. 不要混用制表符和空格。 If you can, use the -tt interpreter option to detect this, and use an editor with an option to display whitespace characters. 如果可以,请使用-tt解释器选项进行检测,然后使用带有选项的编辑器来显示空白字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM