Is there something like "exit(1)" that starts the script from a specific line, like "start(1)"??

Asked by GZ

Is there a command that will start executing my script from a specific line, like "start(1)"??
It would be like exit(1) which stops it at that line of the code, just the other way round..

Say if I want to test my 600 line script from line 101 to 120 I would put the command "start(1)" at line 100 and "exit(1)" at line 121.
This would be amazingly helpful for debugging and checking small parts.

At the moment I have to copy and pastethe parts of my script into a new project to test and then modify the original with my corrections and then copy the midified again to test it.. this process can slow down quite a lot when I have many lines..

Question information

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

Currently we do not have such an option.
I to some extent agree, that it might be helpful in some cases, but surely not as a general approach.

The right way is modularization.
Split up your code in smaller parts, can be developed and tested alone with some setup before and optionally some teardown afterwards.
The modules are packed into scripts, that define callable functions and reusable classes and are made available to the main workflow using import.
The documents and this forum have more infomation.

If you want debugging you have to develop your scripts in a mature IDE like Eclipse.

Revision history for this message
GZ (g-zr) said :
#2

Thanks RaiMan:)

I know, but I would still prefere to have a command like this, so I will add a bug/feature request for it.

Thanks,
G

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

I will set your request to "won't fix", because on one hand such an implementation is rather complex with little effect and might raise other problems, when used.

If some code can be run from line 101, then the code in line 1 - 100 programmatically is totally independent and should be handled as such (if/else/while blocks, classes, defs and/or modules).
Even the simple unit test workflow allows elegant solutions for setting up workflows from smaller parts.

If you want to stick with your approach, the simplest solution is to add a line containing 3 consecutive apostrophes before the first line, that should not run and the same line before the first statement that should be run.
you might add additional trailing text, to easily identify the lines.
this makes all lines between these 2 block comment lines to comment, so they will be skipped at runtime.
So you have your solution with one more line to be added.

Revision history for this message
GZ (g-zr) said :
#4

Thanks a lot RaiMan,

the ''' solution that you have suggested is the one I use since then.

Sorry, I just noticed that I forgot to set this one to solved.. :)

Thanks again,
George