By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,991 Members | 1,737 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,991 IT Pros & Developers. It's quick & easy.

Python as replacement for PHP?

P: n/a
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few features
of PHP I like but overall am not too excited about it. I have found PHP's
strtotime() function to be quite flexible and handy and we make liberal use
of it.

I have not yet really "dug-in" to Python - I have dabbled and hacked a
bit. I am advocating considering switching to Python for a number of
reasons:

1) I think Python is cool.
2) We can do system administration type scripts (currently
implemented in Perl), web page generation (PHP), and (potentially)
client-side applications (including GUI's that make socket and/or external
HTTP requests) in one language.
3) Python's interactive interpreter makes it easy to try things out.
4) PyUnit - we would like to develop a robust set of tests and be
able to do regression testing. I'm not aware of a JUnit/PyUnit analog in
PHP. Are you?
5) Python has better code support for complex native data types
(e.g., tuples, dictionaries, sequences, etc. and being able to write these
directly in a hierarchical structure rather than building them up piecewise
with function calls and assignments as in PHP).
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us,
some probably not. To those that have used PHP: what am I potentially losing
that Python really can't replace?

So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of it,
but I've got a serious business decision to make here).

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?

2) Is there a way to have our cake and eat it too? That is, rather than
being forced to ride one horse or another, can I ride both horses at once:
is there a way to integrate PHP and Python such that I could call PHP
functions from a Python script? I know you can always make system calls, and
it probably wouldn't be that difficult to call an external PHP script and
slurp up it's output from STDOUT, but my impression is that this is a pretty
expensive thing to do (relatively) compared to generating HTML from a single
script invocation. I'm asking if there exists some sort of single-process
integration (e.g., something akin to Java's "native" interface where a
program can schlep data back and forth between a Java environment and
"native" C)?

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.)

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
allows Apache to foist off an HTTP request on a Python script to handle I
assume, but maybe some kind soul can better inform me about what all
modpython really does for me?

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?

6) Debugging: I'm aware there is a debugger for Python - I haven't
really used it. Maybe there is a better way to do this using PHP, but right
now when a PHP script isn't working right, I'm reduced to print statements
and just re-running the script. Do you know a better way to do this in PHP?
If I were doing things in Python, is there an easy way to generate an HTTP
request from my browser, but stop the generating script and analyze it in a
Python debugger?

7) This goes back to #2, but we are looking at purchasing a PHP graphing
package: http://www.aditus.nu/jpgraph/ If we could easily call PHP from
within Python, then I guess that is a no brainer: we can use the PHP
package. If not, then we are left answering the quesiton, can we call it as
a forked process, and if so, is that too expensive? Do you know of
comparable packages for Python?
I think that's it for now. Thank you for taking the time to read my post
and many thanks in advance to anyone who would be so kind as to reply.
(direct response to ej at wellkeeper dot com greatly appreciated).

-ej
Jul 18 '05 #1
Share this Question
Share on Google+
34 Replies


P: n/a
Erik Johnson wrote:
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few features
of PHP I like but overall am not too excited about it. I have found PHP's
strtotime() function to be quite flexible and handy and we make liberal use
of it.
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us,
some probably not. To those that have used PHP: what am I potentially losing
that Python really can't replace?

So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of it,
but I've got a serious business decision to make here).


When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity. We use Python & C for backend processing, systems
administration and other general programming tasks, but the front-end
(the Websites) are pure PHP.
Jul 18 '05 #2

P: n/a
With total disregard for any kind of safety measures "Erik
Johnson" <ej**************@dot.com> leapt forth and uttered:
4) PyUnit - we would like to develop a robust set of tests and
be able to do regression testing. I'm not aware of a
JUnit/PyUnit analog in PHP. Are you?


SimpleTest: http://www.lastcraft.com/simple_test.php
PHPUnit (1):http://www.students.cs.uu.nl/people/voostind/index.php?
page=software
PHPUnit (2):http://pear.php.net/package/PHPUnit
PHPUnit (3):http://phpunit.sourceforge.net/

Having three test suites all called PHPUnit is a tad confusing...
--
Phil Roberts | Dork Pretending To Be Hard | http://www.flatnet.net/
Jul 18 '05 #3

P: n/a
"Erik Johnson" <ej**************@dot.com> wrote in message
news:40******@news.zianet.com...
This is somewhat a NEWBIE question...
(snip)
I have not yet really "dug-in" to Python - I have dabbled and hacked a
bit. I am advocating considering switching to Python for a number of
reasons:

1) I think Python is cool.
2) We can do system administration type scripts (currently
implemented in Perl), web page generation (PHP), and (potentially)
client-side applications (including GUI's that make socket and/or external
HTTP requests) in one language.
3) Python's interactive interpreter makes it easy to try things out. 4) PyUnit - we would like to develop a robust set of tests and be
able to do regression testing. I'm not aware of a JUnit/PyUnit analog in
PHP. Are you?
5) Python has better code support for complex native data types
(e.g., tuples, dictionaries, sequences, etc. and being able to write these
directly in a hierarchical structure rather than building them up piecewise with function calls and assignments as in PHP).
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us, some probably not. To those that have used PHP: what am I potentially losing that Python really can't replace?

(snip)

-ej

You should use what is best for you, but trying to settle on one laguage for
everthing is not a good idea, you will end uplocking yourself into more code
than you need sometimes.

Python is gread for server stuff, and GUI stuff, but for dynamic
intergration of html/script, PHP wins hands down.

Now I also use PHP for everything else (except GUI stuff) on servers, almost
all of my shell scripts are in php, along with autoresponders, mail filters,
data backup servers, etc..

But again, use what is quick/fast/simple to implment for you. I use to use
perl for everthing under the sun, then slowly moved to php, not becouse it
was cool, but rather easier to set up, and with added functions designed for
dynamic site ingration.

You also need to look at what each language was desgined for, sure I can
write a dynamic web page in bash or korn, but why? Perl was written to do
large extraction and reporting of text files, Python was written as a server
language, PHP was design specificly for dynamic/integration of web pages.

Ok, I'm done now.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 18 '05 #4

P: n/a

Erik> 1) PHP seems to have a pretty good integration/driver with
Erik> PostgreSQL. If we were to switch to Python, what
Erik> modules/drivers are available to talk to PosgreSQL and is it as
Erik> functional as PHP's support?

I use psycopg and like it. There are a couple others as well.

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

Marc-Andre Lemburg's mxDateTime might be the closest you'll get to such wide
ranging formats.

Erik> 4) I am vaguely aware of Apache's modpython. We are currently
Erik> running apache, but I'm real green when it comes to
Erik> configuring/running/managing Apache. I don't really understand
Erik> what all modpython does for me. Generally allows Apache to
Erik> foist off an HTTP request on a Python script to handle I
Erik> assume, but maybe some kind soul can better inform me about
Erik> what all modpython really does for me?

It essentially avoids process creation and Python startup overhead. Both
can be significant performance barriers on heavily loaded systems.

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

There are lots of different Python-based templating systems. I like
Quixote. It's roughly the inverse of the way most systems do the
HTML/<language> mind-meld. Instead of Python-in-HTML it's HTML-in-Python.
There are other systems with which I am not aware. Cheetah and PSP come to
mind.

Erik> 6) Debugging: I'm aware there is a debugger for Python - I haven't
Erik> really used it. Maybe there is a better way to do this using
Erik> PHP, but right now when a PHP script isn't working right, I'm
Erik> reduced to print statements and just re-running the script. Do
Erik> you know a better way to do this in PHP? If I were doing
Erik> things in Python, is there an easy way to generate an HTTP
Erik> request from my browser, but stop the generating script and
Erik> analyze it in a Python debugger?

Inserting print statements is a pretty common debugging technique in Python
as well. Also, take a look at the cgitb module.

Skip

Jul 18 '05 #5

P: n/a
Bart wrote:
Erik Johnson wrote:
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few features
of PHP I like but overall am not too excited about it. I have found PHP's
strtotime() function to be quite flexible and handy and we make liberal use
of it.
6) All the other standard evangeslistic points about why Python is
better than <your favorite language here>, some of which may be valid to us, some probably not. To those that have used PHP: what am I potentially losing that Python really can't replace?

So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of it, but I've got a serious business decision to make here).


When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.


What on earth?! Each is entitled to his or her own opinion, but this is a bit
over the top. The OP would do well to search the Google archives as this topic
has come up many times, and there are many who disagree with the above opinion.
Even if in the end the OP decided to stick with PHP (personally I wouldn't),
considering Python definitely does _not_ border on stupidity.

-Dave
Jul 18 '05 #6

P: n/a
Dave Brueck wrote:
Bart wrote:
Erik Johnson wrote:
> This is somewhat a NEWBIE question...
>
> My company maintains a small RDBS driven website. We currently
> generate
> HTML using PHP. I've hacked a bit in Python, and generally think it is
> a rather cool language. I've done Perl and like it, there are a few
> features of PHP I like but overall am not too excited about it. I have
> found PHP's strtotime() function to be quite flexible and handy and we
> make liberal use of it.
> 6) All the other standard evangeslistic points about why Python
> is
> better than <your favorite language here>, some of which may be valid
> to us, > some probably not. To those that have used PHP: what am I potentially losing > that Python really can't replace?
>
> So, I'm hoping there are some people out there that actually have
> some
> expereience with both Python & PHP and can give me some solid, informed
> advice about PHP vs. Python, in general and particularly on the
> following points: (NOT Python evangelism please: I've already heard
> most of it, I've espoused a pretty good dose myself - frankly, I'm
> willing to buy most of it, > but I've got a serious business decision to make here).


When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.


What on earth?! Each is entitled to his or her own opinion, but this is a
bit over the top. The OP would do well to search the Google archives as
this topic has come up many times, and there are many who disagree with
the above opinion. Even if in the end the OP decided to stick with PHP
(personally I wouldn't), considering Python definitely does _not_ border
on stupidity.

-Dave


Sorry, I disagree. As a business decision, it does border on stupidity. Why
contemplate doing something with Python that would be tedious and difficult
at best when PHP can do this task easily and quickly??? From a business
(read practical point of view) it's stupid. From a religious (Mac fanatic
like point of view), it makes sense.

The OP spoke of a DB driven dynamic Web site. One cannot think of such a
thing without naturally thinking of PHP... python should not even come to
mind for this task. Backend/server-side processing, sure, but not on the
frontend. Use the RIGHT tool for the job. Python isn't the right tool here.
Jul 18 '05 #7

P: n/a
Bart Nessux wrote:
When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task.


WTF??

--Irmen
Jul 18 '05 #8

P: n/a
Bart wrote:
Dave Brueck wrote:
Bart wrote:
Erik Johnson wrote: [snip] When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.
What on earth?! Each is entitled to his or her own opinion, but this is a
bit over the top. The OP would do well to search the Google archives as
this topic has come up many times, and there are many who disagree with
the above opinion. Even if in the end the OP decided to stick with PHP
(personally I wouldn't), considering Python definitely does _not_ border
on stupidity.

-Dave


Sorry, I disagree. As a business decision, it does border on stupidity. Why
contemplate doing something with Python that would be tedious and difficult
at best when PHP can do this task easily and quickly???


Specifically which Python templating language(s) have you tried and found to be
"tedious and difficult" to use? Why is it that some people, knowing both PHP
and Python, opt for Python? It's gotta be something more than their own
stupidity. :)

ISTM you're way overstating the gap, if there is one in the general sense. It's
trivial to think of cases where PHP would be the "right" choice and others
where Python would be the "right" choice, so it's hard to put much stock in any
claim that it's so black-and-white, especially when you know so little of the
OP's requirements. Is it one of those "nobody ever got fired for buying IBM"
things? :) I can believe that for some DB driven dynamic web sites PHP would be
better suited, but *always*? No way.
The OP spoke of a DB driven dynamic Web site. One cannot think of such a
thing without naturally thinking of PHP... python should not even come to
mind for this task.
Backend/server-side processing, sure, but not on the
frontend. Use the RIGHT tool for the job. Python isn't the right tool here.


But why? What specifically is it about Python that makes one "stupid" for
considering it? (and does that mean that the many people who *do* use it - and
do so quite successfully - for such tasks are stupid?). Maybe I haven't seen
the light yet, but it's worked pretty well for me.

PHP has some good features, but it's certainly not perfect. Maybe it'd be okay
if it's were your first programming language, for example, but if you are an
experienced developer in other languages then PHP has its own bag of ...er...
surprises (did PHP5 finally fix the horrible copy-on-assignment "feature"?).

I have a friend who made a living for awhile as a "fireman" for PHP
projects-turned-disasters. In assessing the root causes of the disasters, much
of it was attributed to developer sloppiness or lack of experience, but a lot
of it went to language oddities such as weak OO facilities or the
over-encouragement of global variables. Overall the impression was that as PHP
projects grow in size, they tend to get unmanageable at a rate faster than
"normal" (compared to other languages). Anyway, I cite it only because it's a
web developer who has more experience than I do with PHP, but who avoids it in
his own projects due to specific experience with its problems.

There's just no validity to making the claim that the choice is so clear-cut.
Right tool for the job indeed!

-Dave
Jul 18 '05 #9

P: n/a
On Fri, 27 Feb 2004 13:50:09 -0700,
Erik Johnson <ej**************@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
Jul 18 '05 #10

P: n/a
Here's how I see it (I'm a Web Developer by trade):

PHP - excellent database integration, if you don't want to have to use
a Java application server for database work, go with PHP. Also nice
templating system which even the Dreamweaver morons can work with. It
is a bit slow at times (XML-RPC/SOAP implementations stink) and has
limited data types.

Python - excellent GUI support (PyQt/TKinter/wxPython are sooo easy),
best suited to rapid application development - we use it for
prototyping cross-platform C++ apps at work, also for wrapping GUI's
around sysadmin scripts. Plus it's easy to distribute using distutils.

Perl - bloody fast, if you're doing lots of text processing/regex
(e.g. XML parsing) then Perl is it, probably best for sysadmin tasks
too. We use this for large reports at work. I love its hash handling
and wide range of modules.

The moral of the story is don't get locked into one technology, use
the best tools for the job - especially if you happen to know them
all! ;o)
Jul 18 '05 #11

P: n/a
> So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python,


My approach is to use PHP with the Smarty templating system for the
web front end. All program logic and "heavy" lifting (and even
the light lifting) is done by a backend Python program accessed
via XML-RPC. That lets me use each language for what it is best
and most productive at.

Testing is easier since you can do it via XML-RPC.

Roger
Jul 18 '05 #12

P: n/a
In article <L7********************@speakeasy.net>, A.M. Kuchling wrote:
There are several; for some reason I don't really understand, there are
multiple Python/PostgreSQL modules.


The standard module that comes with Postgres was just not keeping up with
the needs of users, so there was a ready audience for other modules. At one
time there were 4: PyGreSQL (the "standard" one), psycopg, PyPgSQL, and
Popy. PyGreSQL has now merged with Popy. I usually use psycopg.

Dave Cook
Jul 18 '05 #13

P: n/a
In article <c1**********@solaris.cc.vt.edu>,
Bart Nessux <ba*********@hotmail.com> wrote:
Jul 18 '05 #14

P: n/a
In article <30**************************@posting.google.com >,
simo <si************@yahoo.co.uk> wrote:
Jul 18 '05 #15

P: n/a
Bart Nessux wrote:

....
Sorry, I disagree. As a business decision, it does border on stupidity. Why
contemplate doing something with Python that would be tedious and difficult
at best when PHP can do this task easily and quickly??? From a business
(read practical point of view) it's stupid. From a religious (Mac fanatic
like point of view), it makes sense.
Hey, god-father!
What enables you to make such all-or-nothing statements.
I'm very impressed by your visdom.

Do you know on which list you are posting? No?
It's name is Python.
This is a list for kind, open people, known to be open for
new ideas, always being open-minded, always talking after
thinking, and they never do thoughtless, absolute statements.
Especially, they never judge about things they have no idea about.

Therefore, I think you can do a much more elaborate, much more
detailed posting, instead of giving such statements, which
nobody can verify, especially if (s)he has different experience.

But I don't really care. Carry on with your own business decision.
Fortunately, it is not my decision, and even better,
I don't depend on it, what a relief! I'm sorry for others who do.
The OP spoke of a DB driven dynamic Web site. One cannot think of such a
thing without naturally thinking of PHP... python should not even come to
mind for this task. Backend/server-side processing, sure, but not on the
frontend. Use the RIGHT tool for the job. Python isn't the right tool here.


Unless you give us some more proof for your statements,
I only can say, with an unhappy absolute statement:

*You are absolutely, completely wrong*.

Please, try to prove your claims or spoil a different list
with such statements. I see no evidence, since I have very
different experience, and I *did* try more than one approach,
before speaking up this way!

For a more friendly reply, see Dave Brueck's post.
I couldn't do that.

annoyed-ly-shutting-up -- chris

p.s.: don't start a flame war. I won't answer. I will also not
begin to give you a private tutorial for free.
--
Christian Tismer :^) <mailto:ti****@stackless.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
Jul 18 '05 #16

P: n/a
In article <40******@news.zianet.com>,
Erik Johnson <ej**************@dot.com> wrote:
Jul 18 '05 #17

P: n/a
On Friday 27 February 2004 01:50 pm, Erik Johnson wrote:
This is somewhat a NEWBIE question...
So, I'm hoping there are some people out there that actually have some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points: (NOT Python evangelism please: I've already heard most of it, I've
espoused a pretty good dose myself - frankly, I'm willing to buy most of
it, but I've got a serious business decision to make here).
Overall my company webme-eng.com has been doing websites/webapps for about 3
years now using zope and we are very happy with it. It has been a very
productive environment to work in and we have worked a lot on frameworks to
make writing our stuff faster. Usually we can do in 1 week what most of our
competitors take about 3 months to do.

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?

I know there is postgres support in python however with zope we have worked
pretty much exclusively with the ZODB which is an object database used in
zope. It has worked well even for sites that have about 2GB of data.
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.)
Zope has a equiv to that that I think does just about all of those if not all
I have not tested all of them and it is part of the standard DateTime object
that is has so it is used pretty much everywhere.

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
allows Apache to foist off an HTTP request on a Python script to handle I
assume, but maybe some kind soul can better inform me about what all
modpython really does for me?
From what I understand mod_python just gets rid of the startup time for each
request. Overall I prefer to have apache proxy for an app server like zope
you might also want to look at twisted.

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 ways to do stuff like that in zope pretty easily. It allows you to
mix in python and your code if you want but it also makes it pretty trivial
to make the items a seperate script object and call that.

6) Debugging: I'm aware there is a debugger for Python - I haven't
really used it. Maybe there is a better way to do this using PHP, but right
now when a PHP script isn't working right, I'm reduced to print statements
and just re-running the script. Do you know a better way to do this in PHP?
If I were doing things in Python, is there an easy way to generate an HTTP
request from my browser, but stop the generating script and analyze it ina
Python debugger?
Zope also logs all errors to an object called error_log in the root of the
site which has the full python traceback and the entire contents of the web
request that generated it. I find that a very useful feature for debugging.
You can also attach a regular python debugger to zope and twisted (iirc).

7) This goes back to #2, but we are looking at purchasing a PHP
graphing package: http://www.aditus.nu/jpgraph/ If we could easily call
PHP from within Python, then I guess that is a no brainer: we can use the
PHP package. If not, then we are left answering the quesiton, can we call
it as a forked process, and if so, is that too expensive? Do you know of
comparable packages for Python?
There are many graphing packages for python designed for many kinds of work.
It should be pretty easy to find one that suits your purpose and use that.


I think that's it for now. Thank you for taking the time to read my
post and many thanks in advance to anyone who would be so kind as to reply.
(direct response to ej at wellkeeper dot com greatly appreciated).

-ej


Overall many people consider zope overkill for most web problems and they are
probably right. It is a huge complex beast but it is also very good at
solving large problems. It has a very flexible security model built into it,
your code runs inside a sandbox unless specifically exempted, there are a lot
of products designed to work with it and a lot of information on using it.

I have no problem recommending zope over php and from what I have read of the
twisted docs for woven I would recommend that over php also. Since python is
not designed as a "web" language I find that overall it has been pretty easy
to build larger solutions since a website is pretty much just a regular app
with an html front end and you can use all the wide ranging features that
python offers such as simpler to read code which makes maintainence easier.
You also gain access to the large library of code available in the form of
stuff like the python imaging library, reportlab, numpy etc.

Jul 18 '05 #18

P: n/a
On 2004-02-27 23:00:44 -0500, cl****@lairds.com (Cameron Laird) said:
In article <40******@news.zianet.com>,
Erik Johnson <ej**************@dot.com> wrote:
.
.
.
some probably not. To those that have used PHP: what am I potentially losing
that Python really can't replace?

.
.
.
The first thing that comes to my mind is the panoply of
data-management bindings PHP builds in. Those who need
to work with a variety of hosting providers like the
comfort of being able to count on the availability of
their favorite DBMS.


Yes, PHP is widely available and easy to find cheap hosting for.
Another additional 'benefit' is that PHP programmers are a dime a dozen
(though you do get what you pay for). However, I can't imagine that
you could make a good living developing software for companies who
can't afford proper hosting, and I've never seen a project get done
properly when you throw a bunch of low quality developers at it.
Python is a LITTLE less esoteric than say, lisp or scheme, so the
argument that it's going to be hard to find good Python programmers to
maintain your software isn't a very good one either.

All that said, PHP is a good language for a beginner. Lots of books
are available that approach the subject from just about any angle, it
is trivial to setup (you don't have to, you find some $5/mo provider to
do it for you, or you buy OS X,), and is so underfeatured that you
couldn't possibly be frightened by its syntax if it is one of the first
few languages you've seen. That doesn't mean it's a good language to
get real things done with though.

Python has its share of problems too, but they typically only surface
if you're not experienced enough (installing packages, finding
packages, learning new APIs, etc.), or if you're TOO experienced
(frustrated about the GIL, lack of multistate, no
macro-like-facilities, standard distribution isn't stackless, little
support for async programming, etc). Python evolves pretty quickly
though, and we're attacking most of these problems at both ends (I'm
personally working on packaging/distribution related matters, and
stackless).

-bob

Jul 18 '05 #19

P: n/a
>>>>> "Simon" == simo <si************@yahoo.co.uk> writes:

Simon> Here's how I see it (I'm a Web Developer by trade): PHP -
Simon> excellent database integration, if you don't want to have
Simon> to use a Java application server for database work, go with
Simon> PHP. Also nice templating system which even the Dreamweaver

So, how do Python's DB modules fall short of those of PHP? If they
indeed do, what should module developers do to fix this gap?

I'm so very tired of the argument that because language X specializes
in doing Q, it must be better than language Y (which is not
specialized for any particular task) for doing Q:

"Perl is only good for doing regexps, therefore it must be better than
Python for doing regexps"

"PHP is only good for doing DB connectivity /Web templating, therefore
it must be better than Python for doing them"

That just isn't logical.

Simon> Perl - bloody fast, if you're doing lots of text
Simon> processing/regex (e.g. XML parsing) then Perl is it,
Simon> probably best for sysadmin tasks too. We use this for large

This is another argument I can't understand. If perl crunches your log
file in 3 minutes and Python takes 4 (but the script remains readable
and maintainable), Python would still be my choice. And regexps for
XML parsing don't always work anyway.

Simon> The moral of the story is don't get locked into one
Simon> technology, use the best tools for the job - especially if
Simon> you happen to know them all! ;o)

Often Python is the best tool for all the jobs there is to do. People
just fail to see that because, driven by prejudice, they opt for the
tool that can *only* do whatever the job is at the moment. That might
have been sensible 15 years ago, but the software landscape has
changed since.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #20

P: n/a
In article <2004022801225916807%bob@redivicom>,
Bob Ippolito <bo*@redivi.com> wrote:
On 2004-02-27 23:00:44 -0500, cl****@lairds.com (Cameron Laird) said:

Jul 18 '05 #21

P: n/a
Bart Nessux wrote:
Erik Johnson wrote:
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently
generate
HTML using PHP. I've hacked a bit in Python, and generally think it is a
rather cool language. I've done Perl and like it, there are a few
features
of PHP I like but overall am not too excited about it. (snip)
To those that have used PHP: what am I potentially
losing
that Python really can't replace?

So, I'm hoping there are some people out there that actually have
some
expereience with both Python & PHP and can give me some solid, informed
advice about PHP vs. Python, in general and particularly on the following
points:

(snip)
When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task.
(snip)
A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.


(snip)

Bart, could you please back your (strong) assertions with at least one
argument ?

AFAIK, there is a whole lot of python tools for web developpement, and I
don't really see any evidence that one of the two languages is more or
less suited to this kind of task.

The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established
- there may be some specific libs not (currently) available in Python.

Bruno

Jul 18 '05 #22

P: n/a

"Cameron Laird" <cl****@lairds.com> wrote in message
news:10*************@corp.supernews.com...
In article <30**************************@posting.google.com >,
simo <si************@yahoo.co.uk> wrote:
.
.
.
Perl - bloody fast, if you're doing lots of text processing/regex
(e.g. XML parsing) then Perl is it, probably best for sysadmin tasks
too. We use this for large reports at work. I love its hash handling

.
Let me get this straight: your preferred vehicle for XML
parsing is Perl regular expressions? That's ... well, it's
a different impression than I've ever gained from anyone
else with deep XML experience. It's sure not my first
instinct.


Not sure what the entire context of this thread is, but I get the impression
that you've misread what he was saying. XML parsing is an example of text
processing, and there are a number of Perl modules that can be used for that
task. Perl probably wouldn't be my first choice for parsing markup languages
(I'd personally use Omnimark), but it is all things to all people.

Matt
Jul 18 '05 #23

P: n/a
Bart Nessux <ba*********@hotmail.com> writes:
Dave Brueck wrote:
Bart wrote:
Erik Johnson wrote:
> This is somewhat a NEWBIE question...
>
> My company maintains a small RDBS driven website. We currently
> generate
> HTML using PHP. I've hacked a bit in Python, and generally think it is
> a rather cool language. I've done Perl and like it, there are a few
> features of PHP I like but overall am not too excited about it. I have
> found PHP's strtotime() function to be quite flexible and handy and we
> make liberal use of it.
> 6) All the other standard evangeslistic points about why Python
> is
> better than <your favorite language here>, some of which may be valid
> to

us,
> some probably not. To those that have used PHP: what am I potentially

losing
> that Python really can't replace?
>
> So, I'm hoping there are some people out there that actually have
> some
> expereience with both Python & PHP and can give me some solid, informed
> advice about PHP vs. Python, in general and particularly on the
> following points: (NOT Python evangelism please: I've already heard
> most of it, I've espoused a pretty good dose myself - frankly, I'm
> willing to buy most of

it,
> but I've got a serious business decision to make here).

When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task. PHP claims to be
a general-purpose language, but I do not know anyone who uses it for
anything other than dynamic Web programming.
It's where php lacks for business decision.

When the application will grow up it will be time to have a clean
design, a standalone server and handle differents protocols. For this
python will be a good choice (look at zope, twistedmatrix, webware,
quixote...).

It's why i had to rewrite a lot of website from php to python. Now, with
delicious template like cheetah, i begin imediatly in python even if
it's overkill for little websites.

Even futur version of php tends to java. With python we have
already all the features of java.

A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders on
stupidity.


What on earth?! Each is entitled to his or her own opinion, but this is a
bit over the top. The OP would do well to search the Google archives as
this topic has come up many times, and there are many who disagree with
the above opinion. Even if in the end the OP decided to stick with PHP
(personally I wouldn't), considering Python definitely does _not_ border
on stupidity.

-Dave


Sorry, I disagree. As a business decision, it does border on stupidity. Why
contemplate doing something with Python that would be tedious and difficult
at best when PHP can do this task easily and quickly??? From a business
(read practical point of view) it's stupid. From a religious (Mac fanatic
like point of view), it makes sense.

The OP spoke of a DB driven dynamic Web site. One cannot think of such a
thing without naturally thinking of PHP... python should not even come to
mind for this task. Backend/server-side processing, sure, but not on the
frontend. Use the RIGHT tool for the job. Python isn't the right tool here.


lol !

--
Wilk - http://flibuste.net
Jul 18 '05 #24

P: n/a
Bruno Desthuilliers wrote:
Bart Nessux wrote:
Erik Johnson wrote:
This is somewhat a NEWBIE question...

My company maintains a small RDBS driven website. We currently
generate
HTML using PHP. I've hacked a bit in Python, and generally think it
is a
rather cool language. I've done Perl and like it, there are a few
features
of PHP I like but overall am not too excited about it.


I've found that the server pages paradigm, used by PHP and ASP, to be
rather limiting when it comes to larger scale web applications. The
paradigm also lends itself to creating spaghetti code (and sites).
Python on the other hand, is quite capable of creating systems not bound
by the convential server page paradigm. It also has powerful facilities
for managing modules, classes and namespaces, which PHP lacks. These
things help out tremendously when it comes to maintenance. Unless PHP
has changed drastically in the last year or so, I believe these
assertions to still be correct.

When it comes to dynamic, DB driven sites, PHP is the only way to go.
Python is not even close to being suited for this task.

I've been programming PHP for much longer than I have been using Python.
After cleansing my mind of the server pages style architecture forced
upon me by PHP, I re-found the fun I used to experience in web
programming. Python is perfect for the job. I've found mod-python a bit
of a chore, so I used twisted web for a while. I've now written my own
server, specifically for handling a REST style architecture. It took me
4 hours to write. It handles gzip encoding and basic authentication.
This is not a testament to my ability, but to the fluidity and power of
Python.
A serious business decision? PHP would be the only winner here. You
should not even be considering another language for this, it borders
on stupidity.

You provide no qualification for this statement. Your admonition to
"not even" consider other languages than PHP is bad advice, and springs
from your own stupidity and/or ignorance.
Regards,

Simon Wittber.

Jul 18 '05 #25

P: n/a
> Bart, could you please back your (strong) assertions with at least one
argument ?

AFAIK, there is a whole lot of python tools for web developpement
The OP was comparing Python to PHP, not ZOPE to PHP. PHP by itself is a
natural Web programming language, Python is not. Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?
The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established


That's exactly right. That's my point. I meant nothing more.
Jul 18 '05 #26

P: n/a
In data Sat, 28 Feb 2004 12:46:13 -0500, Bart Nessux ha scritto:
The OP was comparing Python to PHP, not ZOPE to PHP. PHP by itself is a
natural Web programming language, Python is not. Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?


Since he asked about how to use python for web purposes, one could expect
that he doesn't know what tools are needed to make python one of the best
web programming languages. Zope, Quixote, Cheetah and WebWare, Twisted
with Woven or Nevow (etc.) are all well known products in the python
community.
The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established


That's exactly right. That's my point. I meant nothing more.


<cite>
Sorry, I disagree. As a business decision, it does border on stupidity.
Why contemplate doing something with Python that would be tedious and
difficult at best when PHP can do this task easily and quickly??? From a
business (read practical point of view) it's stupid. From a religious (Mac
fanatic like point of view), it makes sense.
</cite>

Actually it seems you meant that a web solution using python would have
been both difficult and tedious...

--
Valentino Volonghi aka Dialtone
Now using Windows for Notebook Hw failure
X Python Newsreader developer
http://sourceforge.net/projects/xpn/
Jul 18 '05 #27

P: n/a
On 2004-02-28 07:25:46 -0500, cl****@lairds.com (Cameron Laird) said:
In article <2004022801225916807%bob@redivicom>,
Bob Ippolito <bo*@redivi.com> wrote:
On 2004-02-27 23:00:44 -0500, cl****@lairds.com (Cameron Laird) said:

.
[arguments against
positions *I* certainly
don't take]
.
.
All that said, PHP is a good language for a beginner. Lots of books
are available that approach the subject from just about any angle, it
is trivial to setup (you don't have to, you find some $5/mo provider to
do it for you, or you buy OS X,), and is so underfeatured that you
couldn't possibly be frightened by its syntax if it is one of the first
few languages you've seen. That doesn't mean it's a good language to

.
.
.
"OS X"? Panther, or Mac OS X 10.3, does build in an Apache--but
as near as I can tell, it's *not* one which includes PHP. PHP
has to be installed explicitly. Am I missing something?

I'm not ratifying the characterization of PHP as "underfeatured".


By "installed explicitly", do you mean "turned on in httpd.conf"? You
may be right that pre-10.3 didn't include /usr/bin/php (I am not sure),
but mod_php has been standard (just not enabled by default) since at
least 10.1.

When I say grossly underfeatured, I mean the *language* not the *library*.

-bob

Jul 18 '05 #28

P: n/a
On Sat, 28 Feb 2004 03:54:49 -0000, cl****@lairds.com (Cameron Laird)
wrote:
Let me get this straight: your preferred vehicle for XML
parsing is Perl regular expressions? That's ... well,


Rather more restrained a comment than I'd be capable of expressing ?

Jul 18 '05 #29

P: n/a
Bart Nessux wrote:
Bart, could you please back your (strong) assertions with at least one
argument ?

AFAIK, there is a whole lot of python tools for web developpement

The OP was comparing Python to PHP, not ZOPE to PHP.

Neither was I. There are *many* much more web developpement tools in
Python than just Zope.
PHP by itself is a
natural Web programming language, Python is not.
<lol>
How should I understand 'natural' in this context ?
</lol>

More seriously : what does 'natural Web programming language' means ?
Google for dynamic DB
driven programming tools... how may PHP returns vs Python returns are
there?
And ? How does this make Python, I quote : "not even close to being
suited for this task."
The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established

That's exactly right. That's my point. I meant nothing more.


Ho yes you meant more. I still wait for any serious argument to back
your claims that "Python is not even close to being suited for this
task." and that "considering another language " (than PHP) "for this,
(...) borders on stupidity".

Bruno

Jul 18 '05 #30

P: n/a
Bart Nessux schrieb:
The only points I see in favor of PHP are :
- it's a de facto standard, widely used, widely available, and well
established

That's exactly right. That's my point. I meant nothing more.


That's ALL? No preference for specific PHP issues that makes you
choose/recommend it over Python? If youre "stupidity" posting has
anything to do with logic then I must conclude that you consider
everbody who doesn't use the de facto standard (choosing e.g. Linux
over Windows, Python over Perl) bordering on stupidity.

Strange, to say the least.

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplusr.de
-------------------------------------------------------------------
Jul 18 '05 #31

P: n/a
Erik Johnson wrote:

CAUTION: I'm replying as a non-Python programmer.
1) I think Python is cool.
2) We can do system administration type scripts (currently
implemented in Perl), web page generation (PHP), and (potentially)
client-side applications (including GUI's that make socket and/or external
HTTP requests) in one language.
You can do client-side apps in PHP too. Pass the -q option to the CGI
version or just use the CLI version.
GUI - PHP-GTK
Sockets - The socket extension or fsockopen() to treat it as a regular file.
3) Python's interactive interpreter makes it easy to try things out.
? Like the -r option?
4) PyUnit - we would like to develop a robust set of tests and be
able to do regression testing. I'm not aware of a JUnit/PyUnit analog in
PHP. Are you?
5) Python has better code support for complex native data types
(e.g., tuples, dictionaries, sequences, etc. and being able to write these
directly in a hierarchical structure rather than building them up piecewise
with function calls and assignments as in PHP).
In PHP, all these things are essentially arrays and that works fine.
Even the PHP developers say that classes are just syntactic sugar for
associative arrays (that'll change in PHP 5, though). So PHP is
procedural; there's nothing wrong with that.


Not to sound like I hate everything which isn't PHP. It's just that PHP
does have a wide range of functionality and is moving toward
command-line/administration capabilities, and is quite easy to learn if
you know other C-like languages. But if you think that Python better
serves your purpose, then you should use it. Surely, it would be
possible to write a strtotime() implementation in Python; someone may
have already done so.

Jul 18 '05 #32

P: n/a
In article <du*************@amadeus.cc.tut.fi>,
Ville Vainio <vi***@spammers.com> wrote:

Often Python is the best tool for all the jobs there is to do. People
just fail to see that because, driven by prejudice, they opt for the
tool that can *only* do whatever the job is at the moment. That might
have been sensible 15 years ago, but the software landscape has
changed since.


and will change again before you're ready :-(
Use whatever you are happy with that does the job,
just do it so well that the next guy in your position
isn't tempted to rewrite it in his favorite language...
Jul 18 '05 #33

P: n/a
CountScubula schrieb:
You also need to look at what each language was desgined for, sure I can
write a dynamic web page in bash or korn, but why? Perl was written to do
large extraction and reporting of text files, Python was written as a server
language


I don't think so. It seems Python was written as a rapid development
language without a specific application range. That's an advantage
because you can get a lot of different jobs done very well. That's
a disadvantage because there's no no-brainer like "Python is for ...".

A family of marketing phrases comes into mind:

- Python is NOT for device drivers.
- Writing a device driver? Beware of Python!
- OS kernels? Don't even think of Python!
....

:)

Mit freundlichen Gruessen,

Peter Maas

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail pe********@mplusr.de
-------------------------------------------------------------------
Jul 18 '05 #34

P: n/a
Andy Dingley <di*****@codesmiths.com> wrote in message news:<1h********************************@4ax.com>. ..
On Sat, 28 Feb 2004 03:54:49 -0000, cl****@lairds.com (Cameron Laird)
wrote:
Let me get this straight: your preferred vehicle for XML
parsing is Perl regular expressions? That's ... well,


Rather more restrained a comment than I'd be capable of expressing ?


http://www.usingenglish.com/glossary/litotes.html maybe?
Jul 18 '05 #35

This discussion thread is closed

Replies have been disabled for this discussion.