'python pyautogui using multiple try catch is slow
try:
r = [pyautogui.locateCenterOnScreen('pgo.png', confidence=0.77,
region=(0, 0, 361, 514))[0],
pyautogui.locateCenterOnScreen('pgo.png', confidence=0.77,
region=(0, 0, 361, 514))[1]]
except Exception as e:
try:
r = [pyautogui.locateCenterOnScreen('pgo.png', confidence=0.77,
region=(0, 0, 361, 514))[0],
pyautogui.locateCenterOnScreen('pgo.png', confidence=0.77,
region=(0, 0, 361, 514))[1]]
except Exception as e:
try:
r = [pyautogui.locateCenterOnScreen('pgo2.png', confidence=0.77,
region=(0, 0, 361, 514))[0],
pyautogui.locateCenterOnScreen('pgo2.png', confidence=0.77,
region=(0, 0, 361, 514))[1]]
except Exception as e:
try:
r = [
pyautogui.locateCenterOnScreen('pgo.png', confidence=0.77,
region=(0, 0, 361, 514))[0],
pyautogui.locateCenterOnScreen('pgo3.png', confidence=0.77,
region=(0, 0, 361, 514))[1]]
except Exception as e:
pass
everthing work fine but the only problem is it take almost 4 to 6 sec to find an img , is there a way to search multiple img faster ?
Solution 1:[1]
I think python itself is slower than any other languages like C, C++, Java etc.
You are using a library of python which is written in python (don't know exactly may be written in CPython, or any other) which makes it much slower.
One another issue can be Retrieving depends on your system processing speed too.
One solution can be giving the absolute path of the image from root or can be from the home directory.
Note: If pyautogui is searching all the directories and retrieving the image the above may work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harish Madineni |
