473,774 Members | 2,275 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
In article <20040228012259 16807%bob@rediv icom>,
Bob Ippolito <bo*@redivi.com > wrote:
On 2004-02-27 23:00:44 -0500, cl****@lairds.c om (Cameron Laird) said:

Jul 18 '05 #21
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

"Cameron Laird" <cl****@lairds. com> wrote in message
news:10******** *****@corp.supe rnews.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
Bart Nessux <ba*********@ho tmail.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
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
> 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
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
On 2004-02-28 07:25:46 -0500, cl****@lairds.c om (Cameron Laird) said:
In article <20040228012259 16807%bob@rediv icom>,
Bob Ippolito <bo*@redivi.com > wrote:
On 2004-02-27 23:00:44 -0500, cl****@lairds.c om (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 characterizatio n 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
On Sat, 28 Feb 2004 03:54:49 -0000, cl****@lairds.c om (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
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 "considerin g another language " (than PHP) "for this,
(...) borders on stupidity".

Bruno

Jul 18 '05 #30

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
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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...
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.