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?

Data4711
  • 39
  • 4

1 Answers1

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.

Ginty
  • 3,483
  • 20
  • 24
FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28
  • 1
    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 Jul 14 '22 at 07:59
  • @Data4711, I had exactly your same reaction around a year ago! Check other StackExchange communities, like CodeReview, they will leave you amazed. – FLAK-ZOSO Jul 14 '22 at 12:36