R
R
Re7r02022-04-20 16:14:16
Python
Re7r0, 2022-04-20 16:14:16

How can python code be optimized?

there is a python code that uses pyautogui that finds the numbers on the screen:

a = pyautogui.locateOnScreen("img/ef.png", region=(1400, 750, 500, 200), confidence=0.8)

nums = []
nums_dic = {}
conf = 1
numberr = ""
for num in range(0, 11):
    if num == 0:
        conf = 0.9
    if num == 10:
        conf = 0.8
    if num == 6:
        conf = 0.85
    if num == 1 or num == 2 or num == 4 or num == 5:
        conf = 0.8
    elif num == 3:
        conf = 0.77
    elif num == 8:
        conf == 0.85
    elif num == 9:
        conf = 0.8

    for t in find("img/"+str(num)+".png", region=(a[0]+410, a[1], 60, 20), conf=conf):
        if num == 1:
            sv_pos = t
        if num == 10:
            nums_dic[t[0]] = "."
        else:
            nums_dic[t[0]] = num
        nums.append(t[0])
    
    nums.sort()
number = ""
for t in nums:
            
    number = number+str(nums_dic[t])
print(number)


the find function is the same as pyautogui.locateAllOnScreen.
How can it be optimized?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2022-04-20
@Re7r0

You missed num==7. In this case conf is set to 1

confs = [.9, .8, .8, .77, .8, .8, .85, 1, .85, .8, .8]
for num, conf in enumerate(confs):

and remove all if elif below

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question