How to use function if

Asked by Javier Gómez on 2017-02-15

Hi,

I´m trying to use the function "if". I have read in other answer that is necessary to use the function if not exists (__,__) but I did not know how to use it.
I do not know almost anything regarding programming language but I need to understand how it works this function.
What I am trying to do is that the system select an image and if exists the system follow one path and if it does not follow another different.
I would be grateful if anybody can help me with this.

Thanks a lot in advanced

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-02-23
Last query:
2017-02-23
Last reply:
2017-02-19
RaiMan (raimund-hocke) said : #1

"if" is not a function, but a language element of Python scripting language, that allows to add branches to your workflow based on decisions.

If you want to create more complex scripts, you have to get some basic knowledge about the Python language.
There are tons of tutorials in the net.

Only with "scripting by example" you will not get very far and finally end in the pool of frustration.

Nevertheless: have fun with SikuliX.

Of course you should have read at least across the docs of SikuliX:
http://sikulix-2014.readthedocs.io/en/latest/index.html

Javier Gómez (jgomezgav) said : #2

Hi RaiMan,

At first, thanks for answer my question.
Instead of learn all about Python language (I wish learn it, but I really have no time) could you give me an example of this language element?

I wish you could help me with this topic. I want to create a job on Sikulix to automatically do a process once it detect the image and in case that the image doesnt exist follows another path.

Thanks a lot in advanced.

Best RaiMan (raimund-hocke) said : #3

I am sorry, but I have stopped doing things like that, because it takes no end usually: writing the scripts is not my job.

For "if exists()" there are tons of examples in the net.

... and again: you need some basic knowledge. If you do not have the time to get it, then you should try another way.

dinev (ndinev) said : #4

Just to support RaiMan - we can give you "if" exaple but you will stuck almost immediately with another basic problem

However, here is something that will help you with your question
https://www.tutorialspoint.com/python/python_if_else.htm