How to get string of PS into FindFailed exception clause

Asked by Vivek Ayer

Hi,

Suppose I have a try..except clause. This may seem like a stupid question, but I'm able to solve it. I have a screenshot that I know I can't find in the try clause. For logging purposes, how do I get the path of that screenshot once it enters the FindFailed except clause? Somehow use getLastMatch()??

i.e.,

try:
   click(PS)
except FindFailed:
   ?? how to get str(PS) here??

Any help appreciated. Thanks!

Vivek

Question information

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

Not a feature in the moment, you should post a [feature request] bug: match should know it's pattern.

Since I "hated" FindFailed from beginning, I requested exists() ... and got it ;-)

Solution with exists (works with try: except: as well ;-)

img = Pattern or string
if exists(img): click(getLastMatch())
else: print "FindFailed:", img; exit(1)

with exists() you might even go on in your script and take corrective actions in case of FindFailed.

Tip:
for such simple constructs like

try:
   click(PS)
except FindFailed:
   ?? how to get str(PS) here??

I use to make it more readable:

try: click(PS)
except: print "error"; exit(1)

Revision history for this message
Vivek Ayer (vsayer) said :
#2

Actually, since I just want the debug output of FindFailed, which
includes the path name of the image it couldn't find, I can just do
this:

try:
   click(PS)
except FindFailed, debugging:
   print debugging

The debugging output is stored in 'debugging', which I can then play with.

Thanks for the tip!
Vivek

On Tue, Jan 11, 2011 at 11:54 PM, RaiMan
<email address hidden> wrote:
> Your question #141103 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/141103
>
>    Status: Open => Answered
>
> RaiMan proposed the following answer:
> Not a feature in the moment, you should post a [feature request] bug:
> match should know it's pattern.
>
> Since I "hated" FindFailed from beginning, I requested exists() ... and
> got it ;-)
>
> Solution with exists (works with try: except: as well ;-)
>
> img = Pattern or string
> if exists(img): click(getLastMatch())
> else: print "FindFailed:", img; exit(1)
>
> with exists() you might even go on in your script and take corrective
> actions in case of FindFailed.
>
> Tip:
> for such simple constructs like
>
> try:
>   click(PS)
> except FindFailed:
>   ?? how to get str(PS) here??
>
> I use to make it more readable:
>
> try: click(PS)
> except: print "error"; exit(1)
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/141103/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/141103
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Vivek Ayer (vsayer) said :
#3

Thanks RaiMan, that solved my question.