stargeek
PHP news website logo.
home    PHP scripts    articles    seo tools    links    search    contact    shop    realtors


PHP Everywhere: Python vs. PHP?







PHP Everywhere: Python vs. PHP?

PHP Everywhere: Python vs. PHP? 03/30/2005 09:12 AM

From PHP Everywhere today:




This is a GrokNews Entry: (what is grok?)





Similar Items

PHP Everywhere: Python vs. PHP?

Grok Headline matches for PHP Everywhere: Python vs. PHP?

Python and XML: XML Namespaces Support
in Python Tools, Part Two


Python and XML: XML Namespaces Support
in Python Tools, Part Two
05/13/2004 07:55 PM
In his latest Python and XML column, Uche Ogbuji continues his tour of XML namespaces support in Python tools, focusing this time on 4Suite.

Python and XML: XML Namespaces Support
in Python Tools, Part Three


Python and XML: XML Namespaces Support
in Python Tools, Part Three
06/30/2004 07:31 PM
In this month's Python and XML column Uche Ogbuji examines the namespace support in ElementTree, PyRXPU, and libxml.

Backporting from Python 2.3 to Python
2.2


Backporting from Python 2.3 to Python
2.2
06/08/2004 11:18 PM

We have a home-grown templating system at work, which I intend to dedicate an entry to some time in the future. We originally wrote it in Python 2.2, but upgraded to Python 2.3 a while ago and have since been evolving our code in that environment. Today I found a need to load the most recent version of our templating system on to a small, long neglected application that had been running the original version ever since it had enough features to be usable.

Unfortunately, this application was running on a server that only had Python 2.2. Installing Python 2.3 would have been somewhat more painful here than on other servers we run for reasons I won't go in to, so I decided to have a go at getting our current code to run under the older Python version.

In the end, I only had to make three minor changes, all at the top of the file in question.

  1. I added from __future__ import generators as the very first line of the file. We use generators (with the yield statement) in a few places - this feature was only properly added in Python 2.3, but was made available in Python 2.2 as a "future enhancement" through the aforementioned obscure import.

  2. I added True, False = 1, 0 on the next line down. Surprisingly, Python 2.2 had no support for a boolean type and instead used a test for non-zero instead. The above line defines constants that behave enough like Python 2.3's True and False to avoid any problems.

  3. I defined an enumerate function, which was introduced for real in Python 2.3. Here's the code I used:

    
    def enumerate(obj):
        for i, item in zip(range(len(obj)), obj):
            yield i, item 
    

All in all it only took around ten minutes to put the above together, after which the script worked just fine. It was interesting to see how our code had grown to rely on Python 2.3 features without us realising it.


XML with Xen and with Python


XML with Xen and with Python 12/19/2004 03:53 PM
Here is a comment on the paper "Programming with Circles, Triangles and Rectangles" by Erik Meijer et al. Perhaps interesting for XML programmers.

Python-SIP 4.0


Python-SIP 4.0 06/23/2004 12:48 PM
A tool to generate Python bindings from C++ code.

Python-SIP 4.0.1


Python-SIP 4.0.1 07/06/2004 06:45 AM
A tool to generate Python bindings from C++ code.

Another look at PHP and Python


Another look at PHP and Python 02/10/2004 02:46 AM
Postscript: Some people have got the impression from this article that I am moving away from PHP. That is far from the truth. I will continue to use PHP extensively today, tomorrow and for the forseeable future.

I find Python harder than PHP.

It could be because we are programming multi-threaded networked servers in Python, and that could be inherently harder than coding dynamic web-sites. Another reason could be lack of familiarity with Python. For example, I couldn't find the equivalent of htmlspecialchars and other functions, so i had to roll my own.

Despite all these issues, we are continuing to develop this in Python because (AFAIK) PHP does not have stable networking frameworks.

So what do I like about Python?

- Neat Syntax

The use of indentation for compound statements discourages deep nesting, and thus more modular code.

- More Safety Checks

In PHP, when you search using a regular expression, an associative array is returned. In Python, a typed object, "match" is returned when a regular expression search is performed, and not a generic dictionary. You cannot perform arithmetic on strings, an explicit cast is required; neither can you concatenate numbers with strings, explicit typecasts are needed.

- Supports Multi-Threaded Apps

There exists a global lock in Python that prevents multi-threading from working effectively on multiple processors - nevertheless Python has reasonable thread support and allows me to develop reasonably responsive servers.

- Python's Compiler is Standard

Python has a standard compiler and byte-code format. There is no such standard in the PHP world, and most ISP's don't support Zend or Turck MMCache encoded PHP. Better still, a debugger is included in the package too.

- Python Fully Supports Unicode

Python 2.0 and later has full support for unicode. For example to convert big5 to unicode is the simple:

    unicode_str = unicode(tw_chinese_string, 'big5')

In contrast, see how complicated it is to perform double-byte to unicode conversions in PHP (see User Notes).

The only issue i had with the unicode support is that it doesn't come with a complete set of double-byte decoders (eg. big5, gb). After a 20 minute google search, i found this set of python cjk decoders.

And what I dislike about Python

- Python Is Not Rapid Enough?

I think that PHP is a better tool for rapid application development, especially for web-sites. Minor type issues are handled for you transparently in PHP. In Python, once a variable is set, stricter type-checking is performed on most operations.

So you can argue that Python is safer. But PHP coding is definitely more rapid.

Another thing i dislike is that Python's import/load facility does not check .py file modification dates. If i modify a .py file, Python's run-time environment will not recompile it until i restart Python, or perform a reload manually from the command-line interpreter.

- Database Access

Python does not have official database drivers, and you have to select and download these drivers yourself. It's easy to get it wrong. For example, only after coding the adodb_odbc module using PythonWin odbc extension did i realize how awful PythonWin odbc was. I then found the mxODBC extension - unfortunately the mxODBC requires commercial licensing ($75 per CPU).

- Python is Not That Popular

Popularity is relative. There are lots of Python programmers - but there are perhaps 3 times more PHP programmers than Python ones. In Malaysia, the ratio of PHP to Python programmers is probably much worse (10:1?). And there are many training centers offering PHP courses. AFAIK, there are no centers in Malaysia offering Python training. A quick search in monster.com reveals the following (numbers might change over time):

PHP: 131 jobs
http://jobsearch.monster.com/jobsearch.asp?q=php&re=0&sort=rv&tm=&fn=6 60&vw=b&cy=US&brd=1%2C1862%2C1863

Python: 41 jobs
http://jobsearch.monster.com/jobsearch.asp?q=python&re=0&sort=rv&t m=&fn=660&vw=b&cy=US&brd=1%2C1862%2C1863


MPY (MPi for pYthon)


MPY (MPi for pYthon) 06/26/2004 05:20 PM
MPY Version 0.1 Released

Python-SIP 4.1.1


Python-SIP 4.1.1 09/24/2004 03:30 PM
A tool to generate Python bindings from C++ code.

Python 2.3


Python 2.3 10/28/2003 11:06 PM
Python 2.3 was released yesterday... and not a moment too soon. I was just swearing under my breath about this sort of nonsense:
>>> cosmos = technorati.cosmos('http://diveintomark.org/')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "technorati.py", line 214, in cosmos
    xmldoc = minidom.parseString(rawdata)
  File "/usr/lib/python2.2/site-packages/_xmlplus/dom/minidom.py", 
    line 1605, in parseString
    return expatbuilder.parseString(string)
, in parseString
    return builder.parseString(string)
  File
"/usr/lib/python2.2/site-packages/_xmlplus/dom/expatbuilder.py", 
    line 187, in parseString
    parser = self.getParser()
  File
"/usr/lib/python2.2/site-packages/_xmlplus/dom/expatbuilder.py", 
    line 119, in getParser
    self._parser = self.createParser()
  File
"/usr/lib/python2.2/site-packages/_xmlplus/dom/expatbuilder.py", 
    line 734, in createParser
    parser.namespace_prefixes = True
AttributeError: namespace_prefixes
OS X users, don't be discouraged by the mention of there being no MacPython version yet or daunted by the task of compiling it from source -- MacP ython 2.3 lives and is just a few glorious GUI installer clicks away.

Python-SIP 3.9


Python-SIP 3.9 12/08/2003 04:42 PM
A tool to generate Python bindings from C++ code.

Python 2.3.3


Python 2.3.3 12/30/2003 05:13 PM
A high-level scripting language.

Inline-Python-0.21


Inline-Python-0.21 07/27/2004 05:44 AM

Python UnZipped


Python UnZipped 01/05/2004 01:42 PM
Python is a great choice for anyone wanting to play with the increasingly popular ZIP or GZIP (not covered here) file formats, and as usual Python makes it surprisingly fun/easy! Don't believe me? In this article we'll look at creating, extracting, and adding to Zip archives using Pythons standard zipfile module and defining a set of functions you can use with your own Zip files; ending with an example which recursively scans a Zip file and sub-archives.

Javascript from Python


Javascript from Python 12/29/2003 06:51 PM

In a way I'm disappointed to see python-sp idermonkey released. It's a Python wrapper around the Mozilla project's SpiderMonkey Javascript engine which allows Python scripts to execute Javascript code in a rock-solid, battle-tested embedded interpreter.

Why the disappointment? Because just 5 days ago I decided that a Python wrapper for SpiderMonkey would be the ideal project for me to finally attempt to do something productive with C. John J. Lee evidently beat me to it. I can't complain though, as I was estimating a good six months to figure out how to get it all working.

Pettiness aside, this looks like a really valuable project. In addition to being critical for such things as web based unit testing (John's DOMForm does exactly that) it may also provide a useful "sandbox" protected interpreted scripting language for Python projects. Python's own rexec module is meant to provide a safe sandbox for executing potentially hostile code but has been disabled due to potential vulnerabilities. The SeaMonkey Javascript interpreter is tried and tested in this capacity, at least in its incarnation within the Mozilla family of web browsers.


Python Revisited


Python Revisited 01/01/2004 02:44 PM
Happy New Year! Let's talk shop as usual.

Recently, we've been looking at developing some server software in Python. This is my first serious look at Python since 1999, and I'm impressed with the improvements. It's a couple of years older than PHP, and certainly more mature. Python has a reputation for being more rationally designed than PHP or Perl, and in general that's true; but you can still see Python's age in the fact that there are many APIs that do the same thing (eg. the string functions).

PHP is still a better language for web development because it is a simpler language, easy to teach to Java or Javascript programmers, has more flexible string processing, and designed to work well with templates.

But as a general programming language, Python has its advantages. You can build sophisticated networking software with Python that supports threads and asynchronous connections with reasonable efficiency (though Python doesn't really take advantage of multiple CPU's due to an internal global lock). The Twisted and Dibbler frameworks are testament to that. Python's C API is well documented and Python can be easily embedded into 3rd party apps.

Python is also a good source of design ideas. I have noticed that othe rs have realized that many good Java ideas do not translate well to PHP. There is an impedence mismatch; many things that are hard in Java are easy in PHP. It makes sense to create an elaborate framework in Java to do something that's hard in Java, but to apply the same to PHP suggests more energy than sense. In contrast, I suspect that Python and PHP are more complementary than we all suspect...

PS: We also had a look at developing the same server software using .NET. However .NET doesn't have builtin support for open protocols such as POP3 and IMAP. I continue to be amused at the (intentional?) omissions in the .NET framework.


python-gammu 0.3


python-gammu 0.3 01/05/2004 12:22 PM
Python bindings for Gammu.

Python-LDAP 2.0.2


Python-LDAP 2.0.2 07/29/2004 12:57 AM
LDAP modules for Python development/deployment.

Dive Into Python


Dive Into Python 09/08/2004 02:50 PM

Python SOAP


Python SOAP 12/02/2003 02:41 PM
Transition to sourceforge.net

[USN-73-1] Python vulnerability


[USN-73-1] Python vulnerability 02/05/2005 09:38 PM
Martin Pitt (Feb 03 2005)

Python SRS Library 0.30.9


Python SRS Library 0.30.9 08/31/2004 02:50 AM
A Python Sender Rewriting Scheme library.

"the Python Paradox"


"the Python Paradox" 08/13/2004 03:28 AM

Pynfo - Python IRC bot


Pynfo - Python IRC bot 08/08/2004 07:05 PM
Pynfo Unmaintained

Python pie-ing at OSCON


Python pie-ing at OSCON 08/07/2004 05:30 AM
It turns out that the Pythoneers didn't actually wuss out on pie-ing the Perlies at OSCON -- here's the photo-evidence. Lin k

Python milter 0.7.0


Python milter 0.7.0 08/03/2004 04:22 PM
A Python binding for the sendmail milter API with a sample milter.

Python para .NET


Python para .NET 07/30/2004 12:24 PM

Ah, right--new Python::Bytecode


Ah, right--new Python::Bytecode 07/18/2004 12:04 PM
Since I was tired of the fail messages from the CPAN testers, the generic failures on Win32, and needed some reasonable printing for debugging and code analysis, I uploaded Python::Bytecode 2.7 to CPAN. (Or snag it from that link there if you want it)...

Python-Bytecode-2.7


Python-Bytecode-2.7 07/18/2004 05:43 AM

python-gammu 0.4


python-gammu 0.4 01/22/2004 08:38 AM
Python bindings for Gammu.

Exim-Python py1


Exim-Python py1 04/26/2004 06:06 AM
An Exim extension for executing Python functions.

X Python Newsreader 0.2.6


X Python Newsreader 0.2.6 04/24/2004 09:03 AM
An online newsreader with Unicode support.

Python in Mathematics


Python in Mathematics 04/21/2004 09:13 PM

Python in the Mathematics Curriculum by Kirby Urner is something of a sprawling masterpiece. It really comes in four parts: the first is a history of computer science in education, the second an appraisal of the impact of open source on education and the world at last, the third a dive in to the things that make Python so suitable for enhancing the mathematics curriculum and the fourth a discussion of how computer science and traditional mathematics are likely to play off against each other in the field of high school education.

It's a long read, but well worth it. Kirby drops in numerous short Python code samples, such as this neat little implementation of Euclid's algorithm for finding the greatest common denominator of two numbers:


def gcd(a,b):
    while b:
        a,b = b, a % b
    return a

His thoughs on open source and general geek culture are worth digging out even if the main topic of the paper has no interest for you. Here's a sample:

Additionally, I think a key cultural phenomenon is the evolving perception of geek culture as a whole. What many students discover is a global network of loosely organized, yet talented individuals, including many free spirits. The network is cosmopolitan and guided by some newly articulated principles regarding how some forms of intellectual assets should remain freely accessible and reusable. While these values might seem another ideological pipe dream, were they expressed in merely political terms, in this case the lingua franca of the movement is source code, and licensing agreements designed to protect it against leaking off into the proprietary sector. Even though Python may be used in proprietary ways, Python itself remains free.

Kirby presented the talk at Python DC '04 back in March. I wish I'd been there, but the conference was too close to SxSW for me to make it to both.


Python-LDAP 2.0.0


Python-LDAP 2.0.0 05/18/2004 04:41 PM
LDAP modules for Python development/deployment.

Python milter 0.6.9


Python milter 0.6.9 04/20/2004 07:39 PM
A Python binding for the sendmail milter API with a sample milter.

SAX processing in Python


SAX processing in Python 05/26/2004 04:20 AM
An application developer can choose any one of a number of strategies to read and use an XML document. In some very simple examples a script containing a number of regular expressions might do the job, but normally a more rigorous technique is required. The Simple API for XML (SAX) is one of the two key techniques for analysing and processing XML documents (the other is the more complicated Document Object Model (DOM)).

"my Python code"


"my Python code" 06/08/2004 08:54 AM

Python on Panther


Python on Panther 04/09/2004 04:08 PM
Mac DevCenter has an interesting article on using Python with Panther (I wonder who’d win out of those two…), with particular focus on the CoreGraphics library of image manipulation tools. This is an interesting alternative to the PHP/ImageMagick combination which I currently employ on this site.

X Python Newsreader 0.3.0


X Python Newsreader 0.3.0 06/18/2004 02:27 PM
An online newsreader with Unicode support.
Grok Description matches for PHP Everywhere: Python vs. PHP?
GrokA matches for PHP Everywhere: Python vs. PHP?

PHP Everywhere: Python vs. PHP?

The following phrases have been identified by the grok system as matching this entry:

















Also check out:


Grok

Ipod Porn on the
Rise

Brief Abstract of
Wikipedia's
Mesothelioma Cancer
page

Get first aid
instructions in your
cell phone

IE is crap
JSPWiki gains
podcasting support

DevShed: Building a
Template Parser
(Part 2)

Evolt: Higher Search
Engine Positioning
(10 Steps)

Ossur Power Knee
Hilton Hotels
Line-In Alarm Clock

Toshiba First to
Produce Speedy XDR
RAM

DB Sumo Sunriser
Skateboard
Headlights

Ron Jeremy Mobile
with 'Groan Tones'

GeboGebo Wiki 1.1
(Default branch)

SX 1.2 (Stable
branch)

Claroline 1.6 RC1
(Default branch)

DB Solo 0.9.8
(Default branch)

Armangil's
podcatcher 0.2.1
(Default branch)

mntd 0.5.0 (Default
branch)

Enrapture 0.6
(Default branch)

Sigma Six 1.0
(Default branch)

Crossword Formatter
0.2 (Default branch)

Growing Up With
Computers

Uniting carriers
against 'Net attacks

GoToMeeting: Get
Addicted!

Gluehands
NHS accounts joint
venture starts this
week

NCR executive is new
CEO of
Hewlett-Packard

Intel Drives Xeon
Servers Towards
Truland

Former Sask. police
officer charged with
releasing
information from
computers

SAP users get
European forum

Intel reaches out to
internal developers

Intel rounds out
64-bit Xeon
portfolio

So many losers: Will
top HP insiders
leave the company?

Mike Langberg: How
will Hurd's
bottom-line focus
fit with HP Way?

SEC gives guidance
on stock options

Mortal Combat for
PlayStation

Update: HP taps
NCR's Mark Hurd as
new CEO

[RDC] EWB looking
for computer
donations

Intel unveils new
64-bit chip

You May Owe More
Money Soon

Bulgaria's Mobiltel
gets licence for
third-generation
mobile network (AFP)

Norway's 'DVD Jon'
breaks through
Apple's iTunes:
report (AFP)

Ten Thumbs Typing
Tutor 3.0.3 released

MacMagic 1.1 adds
Safari features

Guardian Unlimited |
Special reports |
Iraqi resistance
begins to crack
after elections

Wired 13.04: La Vida
Robot

SCOTUSblog: Court
conflicted over
file-swapping

Where in Washington,
D.C. is Sun Myung
Moon?: Moon: Work
with congressmen to
"discard" democracy

Outlet Radio Network
Strange Dolls
Independent Inquiry
Committee

Linux system
squishes into
Ethernet connector

DenverPost.com -
Technology

libdemthistime.org -
Home

PressThink: Laying
the Newspaper Gently
Down to Die

what is grok?