Spyder does not display class instance variables in variable explorer during python debugging

I am using Spyder v2.2.5 IDE for python programming. When debugging my python code using pdb in spyder, the IDE does not display the class instance variable in the variable explorer. It is difficult to check the values ​​of variables with the print statement every time. Is there a way to check the values ​​of an instance variable of a class during debugging?

+4
source share
2 answers

I know this is an old post, but I found a workaround. Each class object has a dictionary associated with it that contains the assigned variables. This is a little annoying, but you can set the global variable equal to this dictionary, which can be viewed in the Spyder 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 tempdictevery time you change a variable, but this will work.

+1
source

As a workaround, until they fix it, I use local variables inside the method to the very end for debugging. Use the same name, but without the "I". in front of her.

Right before the return statement, I assign local variables to the self. variable equivalent.

, "" . , .

locals .

+1

Source: https://habr.com/ru/post/1548210/


All Articles