Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private variables during debugging

Tags:

People also ask

How do you use private variables?

We can access a private variable in a different class by putting that variable with in a Public method and calling that method from another class by creating object of that class.

What is Debug variable?

Debug Tool reserves several variables for its own information. These Debug Tool variable names begin with a percent sign (%), to distinguish them from program variables. You can access Debug Tool variables while testing programs in any supported language.

Can private variables be accessed in Python?

In Python, there is no existence of “Private” instance variables that cannot be accessed except inside an object.

How are private variables in Python enforced?

In actual terms (practically), python doesn't have anything called private member variable in Python. However, adding two underlines(__) at the beginning makes a variable or a method private is the convention used by most python code.


class Controller:

    def __init__(self):
        self.__whiteList = self.readFile('whiteList.txt')
        a = 0 # Breakpoint

    def getWhiteList(self):
        return self.__whiteList

Well, I placed a breakpoint at a = 0.

When I stop at the breakpoint, I want to evaluate __whiteList.

The error is:

AttributeError:'Controller' object has no attribute '__whiteList'

Well, this is a mystery to me. Because I have the getter method and outside the class it works perfectly.

Well, you may tell me that I could easily take no notice of it as it works outside the class. But I need it during the debugging.

Could you comment on why I can't catch the value at the breakpoint?