John Tantalo wrote:

Is there is a better way to create parameterized classes than defining and returning a class in a closure? I ask because I want to create arbitrary BaseRequestHandler subclasses that delegate line handling to a given line handler, as in this example:

Oh, now I get it. Maybe. Wouldn't it be easier to just use subclassing for parametrization:

    class LineRequestHandler(StreamRequestHandler):
        ...
        self.handle_line(line)

    ...

    class SomeLineHandler(LineRequestHandler):
        def handle_line(self, line):
          print "I got a line: %s" % line

Alternatively, note that the SocketServer framework doesn't require the request handler baseclass to actually be a class; it works with any factory object that takes the same three arguments and returns an handler instance. You can use a plain function closure as a factory, if you prefer that.

</F>

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to