I am trying to run the following HelloWorld Script on the command line
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8888, help="run on the given port", type=int)
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
(r"/", MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
and I get the following error:
File "helloworld.py", line 17, in ?
import tornado.httpserver
File "/home/username/public_html/tornado-1.2.1/tornado/httpserver.py", line 28, in ?
from tornado import ioloop
File "/home/username/public_html/tornado-1.2.1/tornado/ioloop.py", line 184
action if action is not None else signal.SIG_DFL)
^
SyntaxError: invalid syntax
Brand new Python, can anyone explain what the problem is? The helloworld.py postscript is in a directory /home/username/public_html/tornado-1.2.1/, and there is a subdirectory in this directory tornado.
Edit: (ignore this edit now) The command I run is -
python helloworld.py
The result python -Vis
Python 2.4.3
Unfortunately, Tornado does not work with versions prior to 2.5, so this can be a problem. However, I installed Python 2.6.6. How can I make sure that it works with the correct version of Python and not older?
EDIT II
Now I installed Python on 2.6.6
and working
python helloworld.py
produces no output. The program just hangs on the command line.
?