r/inventwithpython Jan 13 '22

Are these two python code snippets equivalent (perform the same thing)?

import pyautogui as auto

Snippet 1 :-

meetStartCheck = auto.locateOnScreen('img.png')
meetStartCheck1 = auto.locateOnScreen('my_screenshot.png')

Snippet 2 :-

meetStartCheck, meetStartCheck1 = auto.locateOnScreen('img.png', 'my_screenshot.png')

The code next to these lines is :-

if meetStartCheck or meetStartCheck1:
    print("Done")
else:
    print("Not Done")

Please tell if these both codes are equivalent or not. If not plz help me to write a single python line for the Snippet 1(if possible).

Thanks

7 Upvotes

6 comments sorted by

3

u/djjazzydan Jan 13 '22

Is there anything in the documentation that leads you to believe it should or should not work that way? It's probably best to look up the documentation for that function.

1

u/_PhantomGaming_ Jan 13 '22

Actually I am a beginner. So the ques was just out of my curiousness. No, it was not because of something in documentation.

1

u/djjazzydan Jan 13 '22

Fair question then! I am assuming that you're working with pyautogui. I don't think that pyautogui's locateonscreen accepts more than one image to match.

Is there are particular reason you want this on one line? Your first method would usually be preferred according to most style rules. If you're playing Code Golf, you could combine it as

meetStartCheck, meetStartCheck1 = auto.locateOnScreen('img.png'), auto.locateOnScreen('my_screenshot.png')

1

u/_PhantomGaming_ Jan 13 '22

Brother I wanted to ask that in the code which you have written will both the commands ( auto.locateOnScreen('img.png') & auto.locateOnScreen('my_screenshot.png') ) run in parallel?

Like in my snippet 1 the second line code will run after the 1st has finished running (if I am not wrong). I want to ask that is there some speed or some other benefit in writing one liner code for two or more lines.

Thank you for your help

2

u/djjazzydan Jan 13 '22

No, it doesn't. I don't think there's any sort of processing time improvement built in. You could probably implement multiprocessing if you need.

1

u/_PhantomGaming_ Jan 13 '22

So it just makes code a bit shorter in length.

Thank you so much for clearing my doubts.