I have a class Conf:
class Conf(object):
def __init__(self):
pass
def __setattr__(self,name,value):
current_container().__set_conf(name,value)
The current_container() returns an instance of the interface class:
class interface(Container):
def __init__(self,name):
pass
def __set_conf(self,name,value):
...
super(interface,self).__set_conf(name,value)
after calling conf.ip=... the exception is arised:
AttributeError: 'interface' object has no attribute '_Conf__set_conf'
It seems that python adding prefix "_Conf" to a method name. How to avoid this?
asked Jan 21, 2014 at 16:50
Pavel
4131 gold badge4 silver badges14 bronze badges
1 Answer 1
You're being victim of name mangling, designed mainly to avoid accidents. If you want to specify that _set_conf method should be private, with only one underscore is sufficiently communicative.
Private Variables and Class-local References provides more information about the utility of this feature.
answered Jan 21, 2014 at 16:53
Paulo Bu
29.9k6 gold badges77 silver badges74 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py