Python 2.7 IndentationError

148 Views Asked by At

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

There are 1 best solutions below

0
AlanK On BEST ANSWER

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'