Strange effect with import
Jens Thoms Toerring
jt at toerring.de
Fri Dec 21 10:52:17 EST 2012
Hans Mulder <hansmu at xs4all.nl> wrote:
> Maybe something like this:
> class ReqHandler(SocketServer.BaseRequestHandler):
> def __init__(self, request, client_address, server, ham, spam)
> super(SocketServer, self).__init__(
> self, request, client_address, server)
> self.ham = ham
> self.spam = spam
> ....
The only thing I had to change about this was to assign the
additional class variables before calling super() because in
the __init__() method of the base class my overloaded handle()
method is already called which needs those extra variables.
> And later:
> import functools
> server = SocketServer.TCPServer((192.168.1.10, 12345),
> functools.partial(ReqHandler, ham="hello", spam=42))
Thanks a lot, that's now all working perfectly well and I got
rid of those pesky global variables;-) Probably the guys that
wrote the SocketServer module indeed didn't expect people as
dense as me to use their module and thus didn't mention that
passing additional information to a handler object can be done
this way...
Best regards, Jens
--
\ Jens Thoms Toerring ___ jt at toerring.de
\__________________________ http://toerring.de
More information about the Python-list
mailing list