Indentationerror: Unindent Does Not Match Any Outer Indentation Level

IndentationError: unindent does not match any outer indentation level

Other posters are probably correct...there might be spaces mixed in with your tabs. Try doing a search & replace to replace all tabs with a few spaces.

Try this:

import sys

def Factorial(n): # return factorial
result = 1
for i in range (1,n):
result = result * i
print "factorial is ",result
return result

print Factorial(10)

unindent does not match any outer indentation level error when compiling the Python code

This error message...

unindent does not match any outer indentation level

...implies that there is a problem with the indentation in your code block.

This error is mostly observed when there is a mixup of Tab and Space characters while indenting Python code.


Analysis

When I copied you code block and executed:

indentation_problem

I got the same error:

C:\Users\username\Desktop\directory\PyPrograms>class_in_python.py
File "C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\class_in_python.py", line 26
def confirmation(self):
^
IndentationError: unindent does not match any outer indentation level

Once, I removed all the white paces and the new line character and break up the line again for the following line of code, the default indentation seems to be different:

     if WebDriverWait(self.driver, 1000).until(
EC.visibility_of_element_located((By.CLASS_NAME, 'succesful'))):
print("Checkout Succesful!")

indentation_difference


Solution

You need to fix up the indentation of the following lines:

  • EC.visibility_of_element_located((By.CLASS_NAME, 'failed'))):
  • EC.visibility_of_element_located((By.CLASS_NAME, 'succesful'))):

You can find a relevant detailed discussion in Is there something issue in indentation, while using Anaconda's Spyder

Unindent does not match any outer indentation level:7

var2 = 56
var3 = int(input())
if var3>var2:
print("Greater")
elif var3==var2:
print("Equal")
else:
print("Lesser")

or if it a problem with the IDE you are using i.e not able to auto-indent please consider installing python code formatter.

Django - error message: IndentationError: unindent does not match any outer indentation level

This type of error could mean that you have mixed spaces and tabs in you indentation, or other whitespace issues.

Is the line below it (line 19) empty or does in have some whitespace?

Python IndentationError unindent does not match any outer indentation level

You are mixing tabs and spaces. Don't do that. Specifically, the __init__ function body is indented with tabs while your on_data method is not.

Here is a screenshot of your code in my text editor; I set the tab stop to 8 spaces (which is what Python uses) and selected the text, which causes the editor to display tabs with continuous horizontal lines:

highlighted code with tabs shown as lines

You have your editor set to expanding tabs to every fourth column instead, so the methods appear to line up.

Run your code with:

python -tt scriptname.py

and fix all errors that finds. Then configure your editor to use spaces only for indentation; a good editor will insert 4 spaces every time you use the TAB key.

error- IndentationError: unindent does not match any outer indentation level

if/elif takes a statement that returns a boolean value.

== is one such operator that checks for equality and returns true/false.

What you have in your code is =, which is an assignment operator and it does not check for equality.

Replace all the if/elif statements like this:

if word == "6":


Related Topics



Leave a reply



Submit