Python for Webscripting (like PHP)

Florian Lindner Florian.Lindner at xgm.de
Fri Aug 19 11:56:57 EDT 2005


Florian Lindner wrote:

> Hello,
> I've been using Python a lot for scripting (mainly scripts for server
> administration / DB access). All these scripts were shell based.
> 
> Now I'm considering using Python (with mod_python on Apache 2) for a web
> project, just how I've used PHP in some smaller Projects before (<?php
> print "foo" ?>)..
> 
> How suitable is Python for these kind of projects? What do think? Does the
> stdlib offers all basic functions for this kind of requirements?

An email I got from Dan Richter. Since he has problems with his news/mail
gateway I forward it with his permission for the benefit of others.

Florian

- - -

Python is great for "heavy lifting": when most of the work is done
behind the scenes and outputting the HTML is relatively trivial. An
example would be a program that searches archives or computes
derivatives.

But PHP is designed for web pages and is quite powerful. If you can
reasonably do a job in PHP, you probably should. Web sites written in
Python usually involve lots of statements like these:
  uri = os.environ['HTTP_URI']
  print '<html><head><title>' + theTitle + '</title></head>'
  print '''<body><div>
              <h1>The answer to your question</h1>
              <p>After lots of computing, here's what 
                 we discovered.</p>'''
And so on. As you can see, PHP allows you to embed HTML much more
gracefully, as well do other web-like things such as retrieve URL query
string parameters more easily. So PHP is preferable for most web sites.

Depending on what you want to do, you might also consider Perl and Java
Servlets.

- - -



More information about the Python-list mailing list