Python as replacement for PHP?

A.M. Kuchling amk at amk.ca
Fri Feb 27 21:42:22 EST 2004


On Fri, 27 Feb 2004 13:50:09 -0700, 
	Erik Johnson <ej.at.wellkeeper at dot.com> wrote:
>     1) PHP seems to have a pretty good integration/driver with PostgreSQL.
> If we were to switch to Python, what modules/drivers are available to talk
> to PosgreSQL and is it as functional as PHP's support?

There are several; for some reason I don't really understand, there are
multiple Python/PostgreSQL modules.  Most of them will support the standard
DB-API described in PEP 249.  Personally I use PygreSQL with Quixote as the
web framework.

Note that I'm one of the developers on a Python web framework called Quixote
(www.quixote.ca), so my answers are slanted in that direction.  If you're in
the Washington DC area, I'll be giving a Quixote tutorial next weekend at a
Linux user group meeting; see novalug.tux.org for meeting details.

>     3) Does Python have an analog to strtotime()? (For those not familiar
> with that function, it converts a wide range of date formats as string into
> time_t value. Can handle things like "now", "+24 hours", "-3 days",
> "yesterday 06:00PM MST", "January 23, 2004", "2004-02-26 18:00:00 -07",
> etc.)

mxDateTime has an extensive parsing module.  There's a PEP for adding date
parsing to core Python, but it may not get done for 2.4.

>     4) I am vaguely aware of Apache's modpython. We are currently running
> apache, but I'm real green when it comes to configuring/running/managing
> Apache. I don't really understand what all modpython does for me. Generally

It embeds a Python interpreter in the Apache daemon, so you can intersperse
Python processing in Apache's request processing.  There's going to be a
mod_python tutorial at the upcoming PyCon conference; again, if you're in
the DC area you might consider going in order to talk to existing Python/web
developers.

Note that embedding the interpreter in Apache isn't a requirement; you can
also run applications using SCGI, or FastCGI instead.  You'd have to carry
out benchmarks to see which one ends up running fastest for your
application.  

>     5) A PHP script can freely jump in and out of static HTML and script
> code with <?php ?>  tags. This is sometimes handy. Can you do the same thing
> with Python?

There are various templating packages available for Python, such as Cheetah
(vaguely PHPish), ZPT (XML-based), or PTL (part of Quixote). Personally I
don't find embedding Python code in HTML to be a good idea; it's too
difficult to refactor, and PTL has various convenient features for
automatically quoting HTML.

> a forked process, and if so, is that too expensive? Do you know of
> comparable packages for Python?

One of the upsides of using Python is that many more non-Web-related
packages have been written for it.  Scientific programming is a significant
application domain for Python, so several graphing packages have been
written. You could use Reportlab for PDF generation, Chaco, Gnuplot, or Gist
for graphing, or the Python Imaging Library for generating PNGs/JPGs.

--amk



More information about the Python-list mailing list