-2

I am new on python and I am trying to do something like this:

import pyautogui
import time

youLocate = pyautogui.locateCenterOnScreen('you.PNG', confidence=0.9, grayscale=False)

time.sleep(3)
if youLocate == "None":
    print("Nothing")
else:
    print("Visible")

The value of youLocate variable according to the console is None string. But instead of printing "nothing", it print the else statement which is "visible".

I also tried to do something like this but did not work:

if print(youLocate) == "None":
    print("Nothing")
else:
    print("Visible")

Is there any ways to get the value of print() so that i can make if statement?

this function: pyautogui.locateCenterOnScreen('you.PNG', confidence=0.9, grayscale=False)

returns "None" according to the console. I want to get the value of it and make it as a variable or compare the value of it using if statement.

Thank you!

ejade
  • 25
  • 7
  • `"None"` is a very different thing from `None`. – user2357112 Dec 08 '21 at 09:57
  • 1
    Does this answer your question? [How to "test" NoneType in python?](https://stackoverflow.com/questions/23086383/how-to-test-nonetype-in-python) – mkrieger1 Dec 08 '21 at 09:58
  • It might not be the string "None" but the object `None` - https://docs.python.org/3/library/constants.html?highlight=none#None – Mortz Dec 08 '21 at 09:58

1 Answers1

0

"None" and None are different things one is a string that contains None and the other is Nonetype so you can compare it like so

if youLocate is None:
    print("Nothing")
else:
    print("Visible")

procoder35
  • 130
  • 6