sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #10077
Re: [Question #194222]: How to get line number from which a function was called in Sikuli?
Question #194222 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/194222
RaiMan proposed the following answer:
Yes is possible by evaluating the stack trace.
But to get it, you first need an exception:
import traceback
def xclick(img):
if exists(img):
click(getLastMatch())
else:
try: raise TypeError
except TypeError:
tb = sys.exc_info()[2]
tbinfo = traceback.extract_tb(sys.exc_info()[2])
print tbinfo # should print a list with entries like
# (filename, line number, function name, some text)
print '[Error] Image not found: ' + img + ' on line' + LINE_NUMBER
exit(1)
But in this case, since you are aborting your script, if the image is
not found, why not use:
def xclick(img):
click(img)
if the search fails, the script will be aborted with exception find
failed and you get your stack trace and the line numbers.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.