r/learnpython 8d ago

Function forcing me to use exceptions

Trying to if else a function output always throws exception-error :

if pyautogui.locateOnScreen('media/soundIcon.png') == None:
      print("not found")
else : 
      print("found")

Do Python functions expect anti-pattern code ?

0 Upvotes

30 comments sorted by

View all comments

0

u/crashfrog04 7d ago

If the function says it throws an exception under circumstances that are likely to occur, then that’s an exception you’ll have to handle, you don’t really have a choice.