0

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.