IndentationError: unindent does not match any outer indentation level

后端 未结 30 2033
Happy的楠姐
Happy的楠姐 2020-11-21 07:48

When I compile the Python code below, I get

IndentationError: unindent does not match any outer indentation level




        
30条回答
  •  执念已碎
    2020-11-21 08:43

    I had a function defined, but it did not had any content apart from its function comments...

    def foo(bar):
        # Some awesome temporary comment.
        # But there is actually nothing in the function!
        # D'Oh!
    

    It yelled :

      File "foobar.py", line 69
    
                                    ^
    IndentationError: expected an indented block
    

    (note that the line the ^ mark points to is empty)

    --

    Multiple solutions:

    1: Just comment out the function

    2: Add function comment

    def foo(bar):
        '' Some awesome comment. This comment could be just one space.''
    

    3: Add line that does nothing

    def foo(bar):
        0
    

    In any case, make sure to make it obvious why it is an empty function - for yourself, or for your peers that will use your code

提交回复
热议问题