Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35301

Re: Strange effect with import

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed101.telia.com!starscream.dk.telia.net!fu-berlin.de!uni-berlin.de!not-for-mail
From jt@toerring.de (Jens Thoms Toerring)
Newsgroups comp.lang.python
Subject Re: Strange effect with import
Date 21 Dec 2012 15:52:17 GMT
Organization Freie Universitaet Berlin
Lines 33
Message-ID <ajjethFsl8gU1@mid.uni-berlin.de> (permalink)
References <ajhbbnFe4q1U1@mid.uni-berlin.de> <50d38d78$0$29967$c3e8da3$5496439d@news.astraweb.com> <ajhj58Ffv64U1@mid.uni-berlin.de> <50d3b34e$0$6889$e4fe514c@news2.news.xs4all.nl>
X-Trace news.uni-berlin.de H+fKcuGC2P5uE07IX+geHA24HaHTZLoihyz3wBAuSub7gIaChqn2naeJgQ4/cq
X-Orig-Path not-for-mail
User-Agent tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.30-1-amd64 (x86_64))
Xref csiph.com comp.lang.python:35301

Show key headers only | View raw


Hans Mulder <hansmu@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@toerring.de
   \__________________________      http://toerring.de

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-20 20:39 +0000
  Re: Strange effect with import Dave Angel <d@davea.name> - 2012-12-20 15:59 -0500
  Re: Strange effect with import Peter Otten <__peter__@web.de> - 2012-12-20 22:11 +0100
  Re: Strange effect with import Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-20 22:13 +0000
    Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-20 22:52 +0000
      Re: Strange effect with import Terry Reedy <tjreedy@udel.edu> - 2012-12-20 19:54 -0500
        Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 01:12 +0000
      Re: Strange effect with import Hans Mulder <hansmu@xs4all.nl> - 2012-12-21 01:54 +0100
        Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 01:25 +0000
        Re: Strange effect with import jt@toerring.de (Jens Thoms Toerring) - 2012-12-21 15:52 +0000

csiph-web