I have follow class:
class Communicator(Thread):
__callback = {
"sender_callback":"__Out",
"listener_callback":"__In"
}
def __init__(self, direction):
Thread.__init__(self)
def run(self):
getattr(self, self.__callback["sender_callback"])(data) # callback is OK
''' some many source code '''
getattr(self, self.__callback["listener_callback"])(data) # AttributeError: 'Communicator' object has no attribute '__servicePercentSetIn'
getattr(self, "_Communicator"+self.__callback["listener_callback"])(data) # callback OK
def __Out(self, data):
pass
def __In(self, data):
pass
Why does getattr with listener_callback raise an exception, when getattr with sender_callback is works fine. Also, why does the third getattr need a class name prefix?
all whitespaces are space, not tab
Python 2.7 and 3.5