Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

HELP python syntaxError: invalid syntax

Featured Replies

Posted
Quote

 


import socket

def Main():
    host = "127.0.0.1"
    port = 5000

    s = socket.socket()
    s.bind((host, port))
    s.listen(1)
    c, addr = s.accept()
    print 'Connection From :' + str(addr)

    while True:
        data = c.recv(1024)
        if not data:
            break
        print "from connected user: "+str(data)
        data = str(data).upper()
        print "Sending" + str(data)
        c.send(data)
    c.close()

if __name__ == "__main__":
    Main()

 

 

the problem is i cannot run and getting this error

wtf.png

i dont get it at all, really need some help 

Cannot see your image, code looks ok. Its python2 maybe u run it with 3?

If you run it on linux, dont use capitals on function names - ur case Main.

def main():

Read:
https://docs.python.org/2/howto/sockets.html

https://www.tutorialspoint.com/python/python_networking.htm
From my very limited python knowledge there is a problem in the way you declare the Main Method:
https://www.guru99.com/learn-python-main-function-with-examples-understand-main.html

So instead of:

def Main():

try lower case mode:

def main():

 

  • Author

thanks in advance

it works now 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.