File "clienttest.py", line 3, in <module>
x = handle.Client()
File "/home/tmac/Handle/handle.py", line 131, in __init__
Task.CLT_UPDATE:self.__clt_updates,
AttributeError: 'Client' object has no attribute '_Client__clt_updates'
my code throws this error when creating an instance but the function exists. It seems to be prepending _Client to it and i cant figure out why
heres the class definition
class Client(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
#create task q
self.tasks = Queue.Queue(maxsize=0)
print str(self)
#create database
self.database = server.Database()
self.database.loadconfig()
#create networking
self.network = network.Network(self.tasks)
#put startup tasks
self.network.cmd_q.put(NetworkCommand(NetworkCommand.CONNECT,('127.0.0.1',self.database.config['Handle']['port'])))
#create gui
self.gui = gui.Gui(self)
#define task handlers
self.handlers = {
Task.CLT_UPDATE:self.__clt_updates,
^----The problem seems to be here--------^
Task.CLT_INPUT:self.__clt_input,
Task.CLT_LINEUP:self.__clt_lineup
}
#define alive flag
self.alive = threading.Event()
self.alive.set()
#setup logging
logging.basicConfig(level=self.loglvl, filename='client.log', format='%(asctime)s %(name)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
self.log = logging.getLogger('CLIENT')
def run(self):
self.network.start()
self.gui.initscreen()
while self.alive.isSet():
try:
task = self.tasks.get(True, 0.1)
self.log.debug('Got Task: ' + task.stype[task.type])
self.handlers[task.type](task)
except Queue.Empty:
pass
def addtask(self, task):
self.tasks.put(task)
def __clt_updates(self, task):
raise NotImplemented()
def __clt_input(self, task):
pack = Packet(Packet.INPUT,task.data)
self.network.cmd_q.put(NetworkCommand(NetworkCommand.SEND,pack))
self.log.debug(':[H]Sent Command: ' + task.data)
def __clt_lineup(self, task):
self.gui.addline(task.data)
self.log.debug(':[H]Line Update: ' + task.data)
Double underscores in Python cause the Python name mangling to kick in at run time. Name mangling will prepend the class name to each method in the class that has a name starting with 2 underscores. If you want privateish methods without name mangling, use single underscore.
As noted below in the comments, it looks like you also have an indentation problem. My guess is that you intend to be creating those methods as class members, but as the question has them here, they are actually indented under
__init__.