Hello Python Syntax

Trying to run simple hello program from
http://webpy.org/cookbook/helloworld
It errors out on line 2 saying 'syntax error near  unexpected token '('.
What am i missing here?

import web

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

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

if __name__ == "__main__":
    app.run()
xoxomosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xoxomosAuthor Commented:
Running on OSX 10.10.
0
clockwatcherCommented:
Unexpected token in line 2 sounds more like an error that you would get from your shell rather than the python interpreter.  How are you running your program?  Make sure you're running it with the python interpreter.  Try running it with this:
python ./helloworld.py

Open in new window

Rather than (what I'm guessing you're doing) this:
./helloworld.py

Open in new window


If you're using the latter, make sure you have a proper python shebang (e.g., #!/usr/bin/python) as the first line to let your shell know to start up the python interpreter.
#!/usr/bin/python

import web

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

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

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xoxomosAuthor Commented:
A206394:REST ctaylor$ python ./hello.py
http://0.0.0.0:8080/
Traceback (most recent call last):
  File "./hello.py", line 13, in <module>
    app.run()
  File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/application.py", line 313, in run
    return wsgi.runwsgi(self.wsgifunc(*middleware))
  File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgi.py", line 54, in runwsgi
    return httpserver.runsimple(func, validip(listget(sys.argv, 1, '')))
  File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/httpserver.py", line 157, in runsimple
    server.start()
  File "/Library/Python/2.7/site-packages/web.py-0.37-py2.7.egg/web/wsgiserver/__init__.py", line 1753, in start
    raise socket.error(msg)
socket.error: No socket could be created
A206394:REST ctaylor$
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

xoxomosAuthor Commented:
I just terminated this 6181
Python    6181           root    3u  IPv4 0x790ae1116214b52f      0t0    TCP *:8080 (LISTEN)
remoting_ 8408        ctaylor   55u  IPv4 0x790ae1116811986f      0t0    TCP 134.154.79.207:55244->173.194.202.125:5222 (ESTABLISHED)
  Then ran again:
A206394:REST ctaylor$ python ./hello.py
http://0.0.0.0:8080/
0
xoxomosAuthor Commented:
OK.  That did it.  Thanks.  Guess it wanted me to put that 8080 in a browser.
0
xoxomosAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.