builtin regular expressions?
John Roth
JohnRoth1 at jhrothjr.com
Sat Sep 30 09:05:25 EDT 2006
Antoine De Groote wrote:
> Hello,
>
> Can anybody tell me the reason(s) why regular expressions are not built
> into Python like it is the case with Ruby and I believe Perl? Like for
> example in the following Ruby code
>
> line = 'some string'
>
> case line
> when /title=(.*)/
> puts "Title is #$1"
> when /track=(.*)/
> puts "Track is #$1"
> when /artist=(.*)/
> puts "Artist is #$1"
> end
>
> I'm sure there are good reasons, but I just don't see them.
Partially it's a matter of language design
philosophy, and partially it's a matter of
the early history of the language.
Guido tends toward a very clean, almost mathematical
minimalist approach: things should be put into the core
language that duplicate other things. Larry Wall tends
toward what I think of as a "kitchen sink" approach.
Put it in!
The other is early history. Python started out as the
scripting language for an operating system research
project at a university. Perl started out as a language
for doing text manipulation in a working systems
administration environment.
There's a different issue that, I think, illustrates
this very nicely: text substitution. Python uses
the "%" operator for text substitution. I suspect
that Guido doesn't like it very much, because it
has recently grown a second library for text
substitution, and there's a PEP for 3.0 for yet
a third library. And guess what? Neither of them
uses an operator.
> Python Culture says: 'Explicit is better than implicit'. May it be
> related to this?
It's more "there should be one, and preferably
only one, obvious way to do something."
John Roth
>
> Regards,
> antoine
More information about the Python-list
mailing list