0

while evaluating self.__properties after self.__properties = {} line it is giving error

AttributeError("testPrivateVariable instance has no attribute '__properties'",),

Should be working, not sure what is wrong. Using python 2.6

import pdb
class testPrivateVariable:    
    size = 524288000    
    def __init__(self, default_properties=None):
        pdb.set_trace()
        self.__properties = {}
        self.__default_properties = {}
        if default_properties != None:
           self.__default_properties = default_properties
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Ram Sharan Mittal
  • 526
  • 2
  • 7
  • 16
  • Nothing is going wrong. That's what's supposed to happen, the point of `__double_leading_underscore` is to invoke name mangling. Try accessing `_testPrivateVariable__properties`, or switch to `_single_leading_underscore`, which indicates private by convention. – jonrsharpe Apr 14 '17 at 07:11
  • @jonrsharpe but following code working 'class Class_demo: def __init__(self): self.__properties = {} print("hi") print(self.__properties) a = "bsc" def sumFun(self, i, j): print(self.__properties) print( i+j) # Class_demo.sumFun( Class_demo(),1, 2) Class_demo().sumFun(3,4)' – Ram Sharan Mittal Apr 14 '17 at 07:48
  • Of course; when accessed via `self` inside the class the name gets mangled for every access. – jonrsharpe Apr 14 '17 at 07:58
  • @jonrsharpe thanks, I was using only__double_leading_underscore without self.__double_leading_underscore , now it working. Got concept – Ram Sharan Mittal Apr 14 '17 at 11:00

0 Answers0