Need some help getting first example to work - syntax err

47 views
Skip to first unread message

Stephen Johns

unread,
Mar 30, 2015, 9:22:11 PM3/30/15
to we...@googlegroups.com
I followed the install page and created the example file:

import web

urls = (
    '/', 'index'
)

class index:
    def GET(self):
        return "Hello, world!"

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

When I run this, I get the following error.  Do I have


./ex.py: line 3: syntax error near unexpected token `('
./ex.py: line 3: `urls = ('

Using
> python --version
Python 2.6.6


Neo Liu

unread,
Mar 30, 2015, 9:43:51 PM3/30/15
to we...@googlegroups.com
It works on my Ubuntu. How did you run this demo?

--
You received this message because you are subscribed to the Google Groups "web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webpy+un...@googlegroups.com.
To post to this group, send email to we...@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.

Dolf Andringa

unread,
Mar 31, 2015, 7:56:50 AM3/31/15
to we...@googlegroups.com
Did you literally paste your code? It works fine for me as well.

vogan

unread,
Mar 31, 2015, 11:48:22 AM3/31/15
to we...@googlegroups.com
The error:
./ex.py: line 3: syntax error near unexpected token `('
./ex.py: line 3: `urls = ('

Is exactly what you get when you run a python script from the command line without an interpreter defined. It is treated as bash script by your operating system and therefore fails.

Try to run "python2 ex.py" or add "#!/usr/bin/python2" at the first line of your ex.py file.
Please note that python2 needs to be replaced by whatever your python2 binary is named.

- vogan 
Reply all
Reply to author
Forward
0 new messages