Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: Show content of hidden parameters for debugging

my core question is: how can I visualize hidden parameters of a class for debugging?
I’m using spyder 3.6 for coding and have e.g. this test code:

class ExampleClass():

    def __init__(self, number):
        self.__hiddenVar = number
        self.visibleVar = number
        print(str(self.__hiddenVar ) + 'at init')

    def plus_2_times_4(x):  
        return(4*(x + 2))

    def arithmetic(self):
        print(str(self.__hiddenVar ) + 'at arithmetic')
        return(ExampleClass.plus_2_times_4(self.__hiddenVar ))

instance = ExampleClass(number = 4)
instance.arithmetic() 

Now I want to stop the run let’s say at the printout of "arithmetic" and debug the content of "self".
When I run "self.visibleVar" in console window of spyder, it shows the conent, in this case "4".
When I do the same with "self.__hiddenVar" it throws an error: *** AttributeError: ‘ExampleClass’ object has no attribute ‘__hiddenVar’

Well, I understand why this is the case: it is a hidden variable and this is how it is supposed to be. But how can I debug in that situation? Do I have any possibility to show the content even though it is a hidden variable?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As the first thing, I would suggest you to read:

To resume the content that you really need, I must say that the interpreter "transforms" __hiddenvar to __ExampleClass__hiddenvar.

1 comments

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading