python web programming for PHP programmers

ajaksu ajaksu at
Wed Dec 24 16:49:53 CET 2008

On Dec 24, 12:40 pm, Nikola Skoric <nick-n... at> wrote:
> I0m a python newbie with PHP background. I've tried to make a web app
> from one of my python scripts (which I haven't done before) and I
> ended up with:
> <?php
> echo shell_exec("python");
> ?>
> which works really nice :-D

Clever :)

Python can work in a similar way to PHP if your server supports it,
but Python also allows you to create the server itself.

> For some reason I can't find no "quick and dirty python web
> programming tutorial for PHP programmers" on google. :-D I don't need
> a general python tutorial, I just need a tutorial on how to make a
> hello world server side script with python. Any suggestions?

See for a very
primitive way (and docs here:

A better way, that uses a trivial Python-based server:
from wsgiref.simple_server import make_server
def hello_app(environ, start_response):
    start_response("200 OK", [('Content-Type','text/plain')])
    return "Hello world!"
httpd = make_server('', 8000, hello_app)
print "Serving HTTP on port 8000..."

$ python
Serving HTTP on port 8000...
localhost - - [24/Dec/2008 13:11:32] "GET / HTTP/1.1" 200 12

You can use better Python-based servers with handy features for

Now, to ease things, you can have Python working more like PHP.

First, server support. What HTTP server are you using? For starting
up, mod_python ( isn't that bad, but there
are better alternatives: , and

Then, there are many ways of getting the PHP feel (embedding in pages,
etc.): (development stopped)


More information about the Python-list mailing list