How can i know what type of arguments go into a function!!!

Saurabh Chadha saurabh at nortelnetworks.com
Fri Dec 14 17:52:27 EST 2001


    Hi all,

    I am just a newbie and was looking at a simple client server
program. Derived from the TCPServer class in (SocketServer module). I am
on version 1.5.2.

    My question is that in order to construct a TCPServer module i have
to pass it in a class derived from BaseRequestHandler class. I have to
override the handle method.
    The code follows below.

>>> class mine(BaseRequestHandler):
...     def handle(self):
...             print self.request, self.client_address,
...             data = self.request.recv(300)
...             while data:
...                     print data, len(data)
...                     data = self.request.recv(300)
...             print "Done"
...
>>> server_address = ('', 22222)
>>> kk = TCPServer(server_address, mine)
>>> kk.serve_forever()

    The code works fine. But it took me a while to figure out how to
print the data. I had to look at other code just to know that
self.request is a socket type and do a type(socket) on it to get to the
functions that are available to me. What strategy are you people using
to determine the type of the object. It does affect my readability since
the i had to plug in dir(self.request) in the code to make sure the type
is a socket.

    Regards,
    Saurabh




More information about the Python-list mailing list