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.
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.
In Python, there is no existence of “Private” instance variables that cannot be accessed except inside an object.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With