Reputation: 413
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?
Upvotes: 0
Views: 161
Reputation: 29794
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.
Upvotes: 2