Learning Python now coming from Perl

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Dec 6 16:50:01 CET 2008


On Sat, 06 Dec 2008 08:50:20 -0500, Roy Smith wrote:

> For your first
> project, pick something that's small enough that you think you could
> tackle it in under 50 lines of Perl.

Is there anything which *can't* be written in under 50 lines of Perl?

:-)


> One of the very first things you'll probably discover that's different 
> between Perl and Python is how they handle string pattern matching.  In 
> Perl, it's a built in part of the language syntax.  In Python, you use
> the re module.  The regular expressions themselves are the same, but
> the mechanism you use to apply them to input text is quite different.

Also, Perl REs are faster than Python REs, or so I'm told. Between the 
speed and the convenience, Perl programmers tend to use RE's for 
everything they can. Python programmers tend to use REs only for problems 
that *should* be solved with REs rather than *can* be solved with a RE.

Well, I say "tend", but in truth we get our fair share of questions like 
"Hi, how do I factorize a 20 digit number with a regular expression?" 
too. 

Probably the biggest difference is that in Python, you always refer to 
objects the same way, regardless of what sort of data they contain. 
Regardless of whether x is a scalar or a vector, you always call it just 
plain x.



-- 
Steven



More information about the Python-list mailing list