builtin regular expressions?

Antoine De Groote antoine at vo.lu
Sat Sep 30 19:14:27 CEST 2006


Just to get it clear at the beginning, I started this thread. I'm not a 
newbie (don't get me wrong, I don't see this as an insult whatsoever, 
after all, you couldn't know, and I appreciate it being so nice to 
newbies anyway). I'm not an expert either, but I'm quite comfortable 
with the language by now. It's just that, when I started Python I loved 
it for its simplicity and for the small amount of code it takes to get 
something done. So the idea behind my original post was that the 
Perl/Ruby way takes even less to type (for the regex topic of this 
discussion, I'm not generalizing), and that I like a lot. To me (and I 
may be alone) the Perl/Ruby way is more "beautiful" (Python  culture: 
Beautiful is better than ugly) than the Python way (in this particular 
case) and therefore I couldn't see the reasons.

Some of you say that this regex stuff is used rarely enough so that 
being verbose (and therefore more readable ?) is in these few cases the 
better choice. To me this a perfectly reasonable and maybe it is just 
true (as far as one can talk about true/false for something subjective 
as this). I dont' know (yet) ;-)

I just have to learn accept the fact that Python is more verbose more 
often than Ruby (I don't know Perl really). Don't get me wrong though, I 
know the benefits of this (at least in some cases) and I can understand 
that one opts for it. Hopefully I will end up some day preferring the 
Python way.

Thanks for your explanations.

Regards,
antoine

Mirco Wahab wrote:
> Thus spoke Jorge Godoy (on 2006-09-30 17:50):
>> Mirco Wahab <wahab at chemie.uni-halle.de> writes:
>>
>> I could make it shorter in Python as well.  But for a newbie that haven't seen
>> the docs for strings in Python I thought the terse version would be more
>> interesting. 
> 
> OK
> 
>> At least he'll see that there are methods to do what he wants already builtin
>> with the language.
> 
> OK
> 
>>> sub print_message {
>>>    if   (/^(track=)/ ){ print 'Your track is '   .substr($_, length $1)."\n" }
> ...
>> If I were writing in Perl I'd not use substr like this and would write code
>> similar to the one the OP posted (i.e., /^track=(.*)/).
> 
> Right, I actually tried to match your example as close as I could
> get and to use only *simple* Regexes (as stated below). What one
> really would do (as you probably meant above) is sth. like:
> 
>   sub print_message {
>      if   (/^track="(.+?)"/ ){ print "Your track is $1\n" }
>      ...
> 
> which has a "more complicated" regex that is usually
> not understood easily by newbies.
> 
>>> OK, I do Perl and Python side by side and didn't reach
>>> that point so far, maybe beause I read the Friedel-Book
>>>  ( http://www.oreilly.com/catalog/regex2/reviews.html )
>>> sometimes and actually *like* the concept of regular expressions.
>> I like them as well.  I just don't see the need to use them everywhere. :-) 
> 
> I like Python for its radically plain look, my
> underlying feeling of Python is: "Pascal", whereas
> Perl feels and tastes like "C" to me ;-)
> 
> Regards
> 
> Mirco



More information about the Python-list mailing list