-1

am using following code to check certain conditions

 for myarg in myargs:
    if myarg=='heading.png':
       t = find(dirpath + '\\' + myarg)
      t1= capture(t.getX() - 50, t.getY() + 50, t.getW(), t.getH())
      click(t1)

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

myargs conatians heading.png,name.png etc

while executing the above code am gettign erros IndentationError: unindent does not match any outer indentation level

3
  • 2
    In your question, your indentation is wrong in so many places. Commented Apr 1, 2014 at 11:38
  • In Python, everything must be properly indented as the error is telling you. Everything after the if block should be at the same indentation until the else block at which point the block after the else should be indented equally to the if block Commented Apr 1, 2014 at 11:39
  • 1
    : is requiered after each block init, else included Commented Apr 1, 2014 at 11:41

3 Answers 3

8

Fix your indentation, you're missing a colon after else and the following print-statement is not indented.

for myarg in myargs:
    if myarg=='heading.png':
        t = find(dirpath + '\\' + myarg)
        t1= capture(t.getX() - 50, t.getY() + 50, t.getW(), t.getH())
        click(t1)

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

I advice using pylint or a similar syntax checker to avoid problems like this.

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

Comments

0

You can easily from your error that there is indentation error.
Change your function to

for myarg in myargs:
    if myarg=='heading.png':
        t = find(dirpath + '\\' + myarg)
        t1= capture(t.getX() - 50, t.getY() + 50, t.getW(), t.getH())
        click(t1)
    else:      # here you must use colon
        print "else inside-----------"

Comments

0

Indentation in Python is, simply put, the equivalent of {} in other languages like C++ and C#.

Don't use text editors to write scripts, you can use rich editors for writing scripts.

   for myarg in myargs:
        if myarg=='heading.png':
              t = find(dirpath + '\\' + myarg)
              t1= capture(t.getX() - 50, t.getY() + 50, t.getW(), t.getH())
              click(t1)
       else:
              print "else inside-----------"

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.