13

I am new to atom, so I opened my existing code using atom and modified few lines, then when I tried running the code with python, I get the following error:

IndentationError: unindent does not match any outer indentation level

I realized that Atom editor does indent my code differently to what I had. refer to the attached picture below showing the different indentation styles. line 1300 is the old indentation and 1301 is the one created by Atom

How can I fix this without modifying my 1000+ line code and so that atom uses the same style of indentation.

enter image description here

1
  • "I realized that Atom editor does indent my code differently to what I had. refer to the attached picture below showing the different indentation styles." - did you understand what text was being used for the indentation in each case? Did you try replacing the wrong indentation, with text that matched the correct indentation? Commented Dec 25, 2023 at 2:36

4 Answers 4

10

You have mixed tabs and spaces in your code. You should use spaces, always.

You can use this plugin to quickly fix your code, and please, use only spaces and 4 spaces for each level of indentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you elaborate on why you should always use spaces instead of tabs?
1

I had a similar error while using Atom,I fixed it using below steps.

  1. Install notepad++

  2. Open the file which has issue(one you have mentioned in question) in notepad++.

  3. Go to View > Show Symbol > Show All Characters,this will show up where the tabs and where spaces are available.

  4. Go to Edit->Blank Operations->TAB to Space to replace all tabs with spaces.

  5. Go to View > Show Symbol > Show All Characters,confirm all tabs are replaced with spaces.

  6. Save file and reload page,this will fix this issue.

Comments

1

In the newer versions of Atom, just go to settings > Editor; then scroll down to tab length and change it to 4; then change tab type to soft. This will make the tab key insert 4 spaces instead of a tab character moving forward. You still have to update your previous code using one of the above methods.

Comments

0

In the Atom Text Editor's top menu bar :

click the Packages tab

click Whitespace in the dropdown menu

Choose your preferred option (ie: Convert Spaces to Tabs)

And that will fix this pesky problem.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.