Issue with Indentation

Asked by Chan Kok Lum

Hi all,

Today will be my worst day working on Sikuli. For some reasons, the simple codes below keeping complaining the error :

[error]Stopped
[error]Error message: IndentitationError:('unindent does not match any outer indentation level',...........py',15,12,'sleep(1)\n

Below are my codes :

CountryFile = open('c:\\temp\\test1.txt')
SourceFile = open('c:\\temp\\test2.txt')

while 1:
    NewCtyCode = CountryFile.readline()
    if not NewCtyCode:
        break

    while 2:
        DetailLine = SourceFile.readline()

        if not DetailLine:
            break
        if exists("3Cratrule.png"):click("3Cratrule.png")
        if exists("1333424884373.png"): <------- if i remove this line and below, everything is fine.
            sleep(1)

If i change the last 2 lines to :
        if exists("1333424884373.png"): sleep(1) <--- this give me "mismatched input" expecting DEDENT

I had double check all the syntax and indentation, but it seems very fine to me.

Any advise ?

Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Chan Kok Lum
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this usually happens, when tabs and spaces are mixed with indentation (see faq 1800)

to paste your code here, does not help (one does not see the tabs and spaces).

If you do not succeed recovering your code, send your zipped .sikuli to my mail or store it somewhere in the net (e.g. the contained .py in DropBox).

Revision history for this message
RaiMan (raimund-hocke) said :
#2

BTW: indentation problems with Python are never funny --- they are like severe headache ;-)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

one more thing:

if exists("3Cratrule.png"): click("3Cratrule.png")

better:
if exists("3Cratrule.png"):click(getLastMatch())

saves you one second ;-) (the additional search with the click)

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#4

From my experience:

1) Better use tabs than spaces for block identation

2) If something goes wrong, use editor which is able to show all characters, even non-symbol ones, and Python syntax highlighting (I use Notepad++ with Win or Komodo Edit on Mac).

Revision history for this message
Chan Kok Lum (chankoklum) said :
#5

Hi RaiMan / Roman,

Thanks for the advices. It solved my problem now.