IndentationError: unindent does not match any outer indentation level

后端 未结 30 1863
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:26

    It could be because the function above it is not indented the same way. i.e.

    class a:
        def blah:
          print("Hello world")
        def blah1:
          print("Hello world")
    
    0 讨论(0)
  • 2020-11-21 08:27

    Just a addition. I had a similar problem with the both indentations in Notepad++.

    1. Unexcepted indentation
    2. Outer Indentation Level

      Go to ----> Search tab ----> tap on replace ----> hit the radio button Extended below ---> Now replace \t with four spaces

      Go to ----> Search tab ----> tap on replace ----> hit the radio button Extended below ---> Now replace \n with nothing

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

    Whenever I've encountered this error, it's because I've somehow mixed up tabs and spaces in my editor.

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

    On Atom

    go to

    Packages > Whitespace > Convert Spaces to Tabs
    

    Then check again your file indentation:

    python -m tabnanny yourFile.py
    

    or

    >python
    >>> help("yourFile.py")
    
    0 讨论(0)
  • 2020-11-21 08:30

    For SPYDER users: I'm using spyder 3.3.2 with python 3.7.1 and I solved this, setting indentation to use tabs, with the following steps, click on:

    • Tools.
    • Preferences.
    • Editor.
    • Advanced settings.
    • Indentation characters -> Tabs.

    Then I reset the "unidented" line using tab key.

    For some reason, without this setting, I got the ghost IndentationError sometimes.

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

    If you are using Vim, hit escape and then type

    gg=G

    This auto indents everything and will clear up any spaces you have thrown in.

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