IndentationError: unindent does not match any outer indentation level

后端 未结 30 2031
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:31

    for Atom Users, Packages ->whitspace -> remove trailing whitespaces this worked for me

    0 讨论(0)
  • 2020-11-21 08:32

    I got this error even though I didn't have any tabs in my code, and the reason was there was a superfluous closing parenthesis somewhere in my code. I should have figured this out earlier because it was messing up spaces before and after some equal signs... If you find anything off even after running Reformat code in your IDE (or manually running autopep8), make sure all your parentheses match, starting backwards from the weird spaces before/after the first equals sign.

    0 讨论(0)
  • 2020-11-21 08:32

    in my case, the problem was the configuration of pydev on Eclipse

    pydev @ Eclipse

    0 讨论(0)
  • 2020-11-21 08:32

    If you use Komodo editor you can do as it suggests in one of similar error messages:

    1) select all, e.g. Ctrl + A

    2) Go to Code -> Untabify Region

    3) Double check your indenting is still correct, save and rerun your program.

    I'm using Python 3.4.2

    0 讨论(0)
  • 2020-11-21 08:34

    For example:

    1. def convert_distance(miles):
    2.   km = miles * 1.6
    3.   return km
    

    In this code same situation occurred for me. Just delete the previous indent spaces of line 2 and 3, and then either use tab or space. Never use both. Give proper indentation while writing code in python. For Spyder goto Source > Fix Indentation. Same goes to VC Code and sublime text or any other editor. Fix the indentation.

    0 讨论(0)
  • 2020-11-21 08:36

    The line: result = result * i should be indented (it is the body of the for-loop).

    Or - you have mixed space and tab characters

    0 讨论(0)
提交回复
热议问题