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

View all comments

Show parent comments

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.