1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This community is really awesome: I ask a question and get an answer within 5 minutes that is really helpful! Great and thanks a lot.
@Data4711, I had exactly your same reaction around a year ago! Check other StackExchange communities, like CodeReview, they will leave you amazed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.