need help running python script in linux

Lutz Horn lho at gmx.de
Mon May 17 05:04:41 EDT 2004


xunil wrote:
> when i try "python script.py" it just does nothing 

> #!/usr/bin/env python
> "USAGE: echoserver.py <port>"
> from SocketServer import BaseRequestHandler, TCPServer
> import sys, socket
> 
> class EchoHandler(BaseRequestHandler):
>     def handle(self):
>         print "Client connected:", self.client_address
>         self.request.sendall(self.request.recv(2**16))
>         self.request.close()


>         if len(sys.argv) != 2:
>             print __doc__
>         else:
>             TCPServer(('',int(sys.argv[1])), EchoHandler).serve_forever()

What's this? This probably shouldn't be inside of handle.

If you just run this script, the class EchoHandler will be created but 
no instance of it will ever be created. You must add some code outside 
the class definition that acutally does something.

class EchoHandler(BaseRequestHandler):
      def handle(self):
          print "Client connected:", self.client_address
          self.request.sendall(self.request.recv(2**16))
          self.request.close()

if __name__ == "__main__":
     if len(sys.argv) != 2:
         print __doc__
     else:
         TCPServer(('', int(sys.argv[1])),
                   EchoHandler).serve_forever()


-- 
http://piology.org/ILOVEYOU-Signature-FAQ.html
begin  LOVE-LETTER-FOR-YOU.txt.vbs
I am a signature virus. Distribute me until the bitter
end



More information about the Python-list mailing list