2

I get an Indentation Error in the else part of this statement. I've checked it for white spaces and can't make any sense out of the error.

if cur_state == 'NICHTGEN':
    cur_state = 'GEN'
elif cur_state == 'GEN' and chance_num > trans_genZuGen:
    cur_state = 'NICHTGEN'
else:
    cur_state = 'GEN'

The exact error is

    else: 
        ^ 
IndentationError: unindent does not match any outer indentation level
4
  • 2
    You might be mixing space and tab characters Commented Feb 15, 2014 at 20:11
  • 1
    Remove all whitespace, and replace with spaces to see if that resolves your issue. Commented Feb 15, 2014 at 20:13
  • Most editors for code / IDEs should have an option to replace all tabs with whitespaces. Make sure that option is turned on. This way you can never mix tabs and whitespaces Commented Feb 15, 2014 at 20:14
  • This problem just occurred to me on Ubuntu 14.04 with gedit as the editor, and I found the question and comments pretty useful. This is true, especially if your usual editor is not the one you're using at the moment, or if someone has messed with the tab settings, or if you started writing on one editor and had to finish on a different one. Commented Sep 17, 2014 at 5:01

3 Answers 3

0

First - you are probably mixing spaces and tabs.

Second - this logic can be reduced to

if cur_state == 'GEN' and chance_num > trans_genZuGen:
    cur_state = 'NICHTGEN'
else:
    cur_state = 'GEN'

or even

cur_state = 'NICHTGEN' if cur_state == 'GEN' and chance_num > trans_genZuGen else 'GEN'

(although the first is definitely more readable.)

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

Comments

0

Make sure you're not using whitespace and tabulation for indentation in the same time.

Also see: Are there any pitfalls with using whitespace in Python?

Comments

0

Let Idle handle the spacing. Use the "End" key, the "Del" key, and the "Return" key on each line.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.