473,773 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python as replacement for PHP?

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
34 3664
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
> 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
In article <L7************ ********@speake asy.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
In article <c1**********@s olaris.cc.vt.ed u>,
Bart Nessux <ba*********@ho tmail.com> wrote:
Jul 18 '05 #14
In article <30************ **************@ posting.google. com>,
simo <si************ @yahoo.co.uk> wrote:
Jul 18 '05 #15
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
In article <40******@news. zianet.com>,
Erik Johnson <ej************ **@dot.com> wrote:
Jul 18 '05 #17
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
On 2004-02-27 23:00:44 -0500, cl****@lairds.c om (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
>>>>> "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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
2874
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville Vainio http://www.students.tut.fi/~vainio24
5
2906
by: Vamsee Krishna Gomatam | last post by:
Hello, I'm having some problems understanding Regexps in Python. I want to replace "<google>PHRASE</google>" with "<a href=http://www.google.com/search?q=PHRASE>PHRASE</a>" in a block of text. How can I achieve this in Python? Sorry for the naive question but the documentation is really bad :-( Regards, GVK
3
9745
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
17
8098
by: DanielJohnson | last post by:
how to use the combination function in python ? For example 9 choose 2 (written as 9C2) = 9!/7!*2!=36 Please help, I couldnt find the function through help.
40
2861
by: walterbyrd | last post by:
I mean other than sysadmins, programmers, and web-site developers? I have heard of some DBAs who use a lot of python. I suppose some scientists. I think python is used in bioinformatics. I think some math and physics people use python. I suppose some people use python to learn "programming" in general. Python would do well as a teaching language.
19
2784
by: John Salerno | last post by:
Hey all. Just thought I'd ask a general question for my own interest. Every time I think of something I might do in Python, it usually involves creating a GUI interface, so I was wondering what kind of work you all do with Python that does *not* involve any GUI work. This could be any little scripts you write for your own benefit, or what you do at work, if you feel like talking about that! :) Thanks.
4
3302
by: Mensanator | last post by:
With the new functions added to itertools in Python 2.6, I can finally get rid of this monstrosity: def ooloop6(a, n, perm=True, repl=True): if (not repl) and (n>len(a)): return r0 = range(n) r1 = r0 if perm and repl: # ok v = ','.join() f = ' '.join()
20
2467
by: Mr.SpOOn | last post by:
Hi, I need a structure to represent a set of integers. I also need to perform on this set some basic set operations, such as adding or removing elements, joining with other sets and checking for the presence of specific elements. I think that using Python sets would be the best choice, but I also need integers to be ordered inside the set and I've just found out that, instead, Python sets are unordered collections.
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.