Why should I switch to Python?

Paul Winkler slinkp23 at yahoo.com
Thu May 11 03:52:19 CEST 2000

> Aaron Turner wrote:
> > What I'd like to hear from people is what technical
> > resons I should switch to Python.  Are there any
> > features that Python has (perhaps in it's OO
> > offering) that Perl lacks?  From what I can tell
> > people tend to prefer Python over Perl mostly
> > for its syntax, which I find very likable.

Two big ones come to mind: using complex data structures, and
modularizing your code. Both are much easier in python.

Suppose you want to make a dictionary ("hash" in perl-land) using
strings as keys and lists as values. In python it's simple enough
that I can fire up the interpreter and get it right on the first
try, like this:

>>> friends={'Bob': [], 'Jane': ['Lisa', 'Mabel', 'Freddy'], 'Lisa':['Mabel']}  >>> for name in friends.keys():
...     print name, "has these friends:"
...     for f in friends[name]:
...             print " ", f,
...     print
Bob has these friends:

Lisa has these friends:
Jane has these friends:
  Lisa   Mabel   Freddy

In perl, doing this is so painful to me that I'm not even going to
try it now, and it only gets worse as your data structures get more

After that, I'd say the biggest advantage to python is that
modularizing things takes no special effort at all (you just put the
code in a separate file!), whereas you have to do quite a bit of
fiddling in Perl.

I also really like python's error tracebacks. I've never had to use
the python debugger (admittedly, my projects are small).
Many of my smaller scripts work right the first time I run them, and
for the rest I just read the tracebacks. Took me a while to get used
to understanding them, but now it's no trouble. 

What I miss from perl: I'd say using perl as a shell scripting
language is faster. Python has all the same features but they're
often implemented as functions or classes in the standard library,
rather than as special punctuation, so there's more typing to do.
And if you learn both languages from the O'Reilly "Learning P*"
books, you have to get farther into "Learning Python" before you
find out how to do those things, as compared to "Learning Perl".
OTOH, you've learned a lot more about python than you have perl if
you finish both books.

................    paul winkler    ..................
slinkP arts:   music, sound, illustration, design, etc.
A member of ARMS    ----->    http://www.reacharms.com
or http://www.mp3.com/arms or http://www.amp3.net/arms
personal page   ---->    http://www.ulster.net/~abigoo

More information about the Python-list mailing list