How to get value of parent class

Jean-Pierre Bergamin james at ractive.ch
Mon Apr 12 09:27:02 EDT 2004


Hello

I have the following class structure:


class MyServer:

    x= 0

    class MyHandler(SocketServer.StreamRequestHandler):
        def handle(self):
            if x: # <---- How to get the X from the parent class?
                  # Or how to pass a value to this class anyway?
                do_something()
            else:
                do_something_else()

    def start_server(self):
        s = SocketServer.TCPServer(('', 1234), self.MyHandler)
        s.server_forevert()

server = MyServer
server.x = 10
server.start_server()



How is it possible to get the value of x from the class MyServer within the
MyHandler class?
The object of self.MyHandler is instantiated everytine the
SocketServer.TCPServer calls handle, so it's not possible to create an
instance of MyHandler an pass it the value.

Or ist there any other possibility to pass the class MyHandler some values?


Thanks in advance.


James





More information about the Python-list mailing list