perl to python

Roy Smith roy at panix.com
Thu May 13 17:44:25 EDT 2004


"Andy Baker" <andy at andybak.net> wrote:

> Here is a small feline amongst the pigeons...
> 
> Surely support for regular expressions is 'un-pythonic'?
> 
> The Python way would be to code regex's explicitly, surely?


In what way is Python's support for regex's un-pythonic or un-explicit?

Regex support is similar to SQL support.  Both are little languages (in 
the case of SQL, maybe not so little), with syntax and semantics finely 
tuned for a specific purpose, and defined/standardized by entities 
outside of the Python community.  To a certain (lesser) extent, LDAP 
support falls into the same category.

The common theme here is that the operation you want to perform is 
defined entirely by a text string.  If I want to search for 
"((spam)|(eggs)|(bacon)){10,}", that is the exact string I want to use, 
regardless of the host language.  This implies that you either need to 
build knowledge of regex syntax into the core language (like Perl, sed, 
and awk do), or you need to pass strings down into functional API (like 
Python, C, and Java do).

I don't think anybody can deny that building regexes into the language 
makes it more convenient.  The problem is, where do you stop?  Do you 
also build SQL support right into the language?  LDAP?  For each 
individual extension, it sure would be convenient for performing certain 
specific tasks, but the overall result would be a mess.



More information about the Python-list mailing list