I am using Spyder v2.2.5 IDE for programming python. While debugging my python code using pdb in spyder, the IDE does not show the class instance variable in Variable Explorer. It's getting difficult to check the variable values using print statement every-time. Is there any way to check the class instance variable values during debugging?
Go to View/Panes and select Variable Explorer. Save this answer.
To see them all, double click the list to open a viewer that will display the index, type, size and value of each element of the list. Just like dictionaries, you can double-click values to edit them.
To trigger a refresh, simply click the reload button on the Variable Explorer toolbar, or press the shortcut Ctrl+R ( Cmd-R ) when it has focus.
I know this is an old post, but I did find a temporary solution. Every class object has a dictionary associated with it that contains the assigned variables. It is a little annoying, but you can assign a global variable to be equal to that dictionary which can be viewed in Spyder's variable explorer.
import numpy as np
class someClass:
def __init__(self):
self.var1=10 #integer type
self.var2=np.ones((3,3,3)) #numpy array type
self.var3=[np.ones((2,2,4))*i for i in range(5)] #list type (of numpy arrays)
b=someClass()
tempdict=b.__dict__ #Then look at this variable under the Variable explorer
You will need to update tempdict
every time you change any of the variables, but this will work.
As a temporary solution until they fix this, I am using local variables inside the method until the very end for debug. Use the same name, but without the "self." in front of it.
Right before the return statement, I assign the local variables to the "self." variable equivalent.
If I need the values of a prior, existing "self." variable during execution , then I assign it to a local variable in the beginning of the method.
After debug phase is complete, you can replace the locals with the proper class attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With