if/else语句中的Python缩进错误

kam*_*mal 0 python syntax

对于以下代码:

if __name__ == '__main__':
    min_version = (2,5)
    current_version = sys.version_info
if (current_version[0] > min_version[0] or
    current_version[0] == min_version[0] and
    current_version[1] >= min_version[1]):
else:
    print "Your python interpreter is too old. Please consider upgrading."
    config = ConfigParser.ConfigParser()
    config.read('.hg/settings.ini')
    user = config.get('user','name')
    password = config.get('user','password')
    resource_name = config.get('resource','name')
    server_url = config.get('jira','server')
    main()
Run Code Online (Sandbox Code Playgroud)

我收到错误:

 else:
       ^
IndentationError: expected an indented block
Run Code Online (Sandbox Code Playgroud)

Ian*_*and 6

if的if语句中没有任何内容.你的代码直接跳转到else,而python期待一个块(一个"缩进块",准确,这就是它告诉你的)

至少,你需要一个只有'pass'语句的块,如下所示:

if condition:
    pass
else:
    # do a lot of stuff here
Run Code Online (Sandbox Code Playgroud)

但是,在这种情况下,如果你真的不想做任何事情if,那么这样做会更清楚:

if not condition:
   # do all of your stuff here
Run Code Online (Sandbox Code Playgroud)