Python 2.7 IndentationError [closed]

半腔热情 提交于 2019-12-12 10:32:28

问题


I am getting an IndentationError when trying to run my program in a Python Interpreter:

 line 127
    global map
         ^
IndentationError: expected an indented block

I am using python version 2.7

What's wrong with the following code?:

def make_map():
global map

回答1:


Python expects 4 spaces or a tab to indent and align code - similar to Java expecting curly {} brackets are the start of a loop, method or class etc.

def some_function():
somecode
morecode
...

should be formatted as

def some_function():
    somecode
    morecode
    ...

It appears that your code throws an exception on line 127, so check this and indent the code as required.

def some_code():
    for i in range(1, some_value):
        some_method()

        if need_more_indent:
            indent_code()

        do_this_after_indent_code()

    this_runs_after_for_loop()

    return 'lol'


来源:https://stackoverflow.com/questions/38405772/python-2-7-indentationerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!