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 Answer
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
1 Comment
Simon
Thank you so much! I'm still a beginner so I have a lot to learn...