Private variables during debugging

class Controller:

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

    def getWhiteList(self):
        return self.__whiteList

Well, I set a breakpoint at a = 0.

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

Error:

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

Well, this is a mystery to me. Since I have a getter method outside of the class, it works just fine.

Well, you can tell me that I could easily ignore this, since it works outside the classroom. But I need this during debugging.

Could you comment on why I cannot catch the value at the breakpoint?

+4
source share
2 answers

, Python "" , _<classname>. , :

def getWhiteList(self):
    return self._Controller__whiteList

__whiteList.

, __ . whiteList:

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

def getWhiteList(self):
    return self.whiteList

:

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

def getWhiteList(self):
    return self._whiteList

, _whiteList .

, , getWhiteList , whiteList. . Python, 99% , .

+4

print self.getWhiteList() print self._Controller__whiteList.

-> a = 0 # Breakpoint
(Pdb) list
  1     class Controller:
  2  
  3         def __init__(self):
  4             self.__whiteList = self.readFile('whiteList.txt')
  5 B->         a = 0 # Breakpoint
  6  
  7         def getWhiteList(self):
  8             return self.__whiteList
  9  
 10         def readFile(self, x):
 11             return x
(Pdb) print self
<__main__.Controller instance at 0x106d200>
(Pdb) print self.getWhiteList()
whiteList.txt
(Pdb) print self._Controller__whiteList
whiteList.txt
0

All Articles