0

When I run this helloworld code I get a "No socket could be created" error.

import web

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'


app.run()

The same cod works fine if I enclose the call to app.run() inside of an if statement like this

if __name__ == "__main__":
  app.run()

My understanding is that it shouldn't make any difference. Anyone have an explanation?

Aaron
  • 2,354
  • 1
  • 17
  • 25

1 Answers1

0

if you run a py file in command line,the default __name__ attribute will be __main__,and your code is executed from top to bottom.You can refer to this question What does if __name__ == "__main__": do?

Community
  • 1
  • 1
pigletfly
  • 1,051
  • 1
  • 16
  • 32
  • I understand that. But shouldn't the behavior be equivalent with or without the app.run() being enclosed in an if statement given that I am running from the command line? – Aaron Nov 20 '15 at 21:37