473,774 Members | 2,252 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 3666
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********@mplu sr.de
-------------------------------------------------------------------
Jul 18 '05 #31
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
In article <du************ *@amadeus.cc.tu t.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
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********@mplu sr.de
-------------------------------------------------------------------
Jul 18 '05 #34
Andy Dingley <di*****@codesm iths.com> wrote in message news:<1h******* *************** **********@4ax. com>...
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 ?


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

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
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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
10267
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
8939
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...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
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.