To check if a global variable exists (and if so, delete it) I have been using this method:
if 'y' in globals():
y.remove()
But I get the following error:
ValueError: list.remove(x): x not in list
This method has worked for me in the past, I don't understand why the if statement accepts the statement as true, which implies 'y' exists, and then tells me 'y' does not exist. Is there a fix or even a completely different method of doing this? For context, 'y' is part of a scatter plot on a matplotlib.figure plot, which is embedded in a canvas for a tkinter GUI.