0

while i trying to execute following code

for value in jsondata:
    command = value['command'] 
    val = value['value'] 
    print command
    print val

    if command=='sel_media':
        t = find(dirpath + '\\' + myarg)
        t1= capture(t.getX() - 50, t.getY() + 50, t.getW(), t.getH())
        click(t1)

    else:

        print "else inside-----------"

am getting

else:
^
indentationError: unindent does not match any outer indentation level

i dont know why it is happening? please correct me

3
  • Python differentiates between spaces and newlines, be consistent. I have this problem sometimes Commented Apr 2, 2014 at 9:02
  • I suspect it may be due to your if being indented with a tab and your else being indented with spaces Commented Apr 2, 2014 at 9:02
  • I suggested that you use pylint in my answer to your previous question. Pylint should give you a warning if you have mixed indentation of tabs and spaces. Commented Apr 2, 2014 at 9:07

4 Answers 4

2

Your code is probably mixing tabs and spaces for indentation.

Just set your editor to never use tabs. All decent programming editors have this option.

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

1 Comment

Go to Settings | Preferences... | Language Menu/Tab Settings and make sure Replace by space is checked.
0

Please check all blanks in your file ans spaces not tab. If you have vim editor you can check by :set list command.

Comments

0

This is probably due having a tab in your code somewhere. Python treating tabs as 8 spaces, but your editor is probably set up to display them as 4 spaces. try using python -t which will give you an error if you use a tab character.

Comments

0

Set your code editor to use spaces instead of tabs and set those tabstops to 4. Python uses 4 spaces to differentiate between code blocks. Also you can try using sublime, it does this autoatically according to file types. You can also try to manually put 4 spaces and then wrtiting your code accordingly. Hope it helps.

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.