-1

I have built a python script with selenium that checks a certain website for a number. Whenever I run the script it returns the updated number from that website and puts it in a variable. But how can I detect when the variables value has changed and how to print something when it has changed?

1
  • Create a prev variable and compare it with current number returned. Commented May 15, 2021 at 18:32

1 Answer 1

0

Could have another variable like prevVar and do something along the lines of

prevVar = 0
watchVar = 0

while True:
    # Do stuff that updates watchVar
    if prevVar != watchVar:
        print("Value has updated to something different")
        # Update prevVar to the new watchVar
        prevVar = watchVar

Just using a second variable to track the previous variable's value.

Edit: This is also based on the assumption you mean a local value and not the variable from the site being checked with selenium.

There's a similar question here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I'm still a beginner so I have a lot to learn...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.