Syntax error in python 2.3.4

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akilasekaran
    New Member
    • Feb 2012
    • 15

    #16
    oh sorry.. i am new to the forum.. ll use code tag :)

    Comment

    • akilasekaran
      New Member
      • Feb 2012
      • 15

      #17
      i tried using indentation.. but the error comes in the print line following the client accept code. i.e 2nd line from try. :(

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #18
        No problem. Code formatting does not display properly unless code tags are used. You can easily add them by selecting the text you want to wrap in tags and picking the "#" button at the top of the reply widget.

        Comment

        • akilasekaran
          New Member
          • Feb 2012
          • 15

          #19
          i rectified the error myself :) thanku sooo much.. :)

          Comment

          • akilasekaran
            New Member
            • Feb 2012
            • 15

            #20
            the error was all about indentation and proper port mentioning :-)

            Comment

            • bvdet
              Recognized Expert Specialist
              • Oct 2006
              • 2851

              #21
              I suspect it is still an indentation problem. Your indentation should look like this:
              Code:
              from socket import *
              s = socket(AF_INET,SOCK_STREAM) 
              h=gethostbyname(gethostname())
              print 'host is ',h
              s.bind((h,9000))
              s.listen(1)
              while 1:
                  try:
                      client, address = s.accept()
                      print 'connection from', address
                      data = client.recv(1024)
                      if not data:
                          break 
                      client.send(data) 
                      client.close()
               
                  except IOError:
                      print'IOError is there !'
                      client.close()
              Note that the number of spaces representing an indentation is a matter of preference but should be consistent. I prefer 4 spaces. Also note it is bad practice to mix spaces and tabs.

              Comment

              • akilasekaran
                New Member
                • Feb 2012
                • 15

                #22
                oh okays :) got it :)

                Comment

                Working...