asyncore.dispatcher python module error -
i started learning asyncore.dispatcher module , when run first example program gives below error.
python version 2.6
asyncore module installed , there dispatcher class inside it. may problem !
error :
attributeerror: 'module' object has no attribute 'dispatcher'
example code :
import asyncore, socket class httpclient(asyncore.dispatcher): def __init__(self, host, path): asyncore.dispatcher.__init__(self) self.create_socket(socket.af_inet, socket.sock_stream) self.connect( (host, 80) ) self.buffer = 'get %s http/1.0\r\n\r\n' % path def handle_connect(self): pass def handle_close(self): self.close() def handle_read(self): print self.recv(8192) def writable(self): return (len(self.buffer) > 0) def handle_write(self): sent = self.send(self.buffer) self.buffer = self.buffer[sent:] client = httpclient('www.python.org', '/') asyncore.loop()
your problem named file asyncore.py
. it's shadowing asyncore.py
in python standard lib file importing instead of real one. want rename copy of file , delete asyncore.pyc
in same directory if exists. when run file, you'll importing asyncore.py
standard library.
when python runs line import asyncore
, python looks through directories in sys.path
file named asyncore.py
. directory of primary file that's executing first entry in it. python finds file , attempts import it. general rule, should never give files same name module standard library if want use module.
Comments
Post a Comment