[Tutor] Regex's and "best practice"
Carl D Cravens
raven at phoenyx.net
Sun Nov 23 13:39:25 EST 2003
On Sat, 22 Nov 2003, Karl [iso-8859-1] Pfl=E4sterer wrote:
> Without a little bit cheating you will have more verbose code with
> Python. But that's nothing new nor should it be a hindrance (if the
> number of lines doesn't differ too much).
I recognize that... took me awhile to get used to, though. It's been a
long time since I've done serious C coding, and I've forgotten just how
much "magic" and assumption there is in Perl. When I first started
with Python (just a week ago), I was dumbfounded that an end-of-file
condition raised an exception and terminated the program if it wasn't
handled. Didn't exactly seem convenient at all. Of course, I then
discovered that various modules dealt with reading files more elegantly.
'import this' puts a lot of things in perspective. And fileinput is
> You could at first use search() instead of sub().
Seems that doing two regex operations instead of a simple string
comparison and a regex operation is both easier to code and simpler to
> That would mean you had to rewrite the regexps a bit. Second you could
> use named groups (a nice thing in Python) instead of the numbers.
> Third you could write one or two functions which give you the terseness
> of Perl.
Terseness in the main code, yes... but overall I'd have to write more code
to develop functions which don't get used anywhere but here.
I'm not following your code... I need to go read about groups.
My primary purpose in posting was to be sure that I wasn't missing some
Carl D Cravens (raven at phoenyx.net)
Press any key to continue or any other key to quit.
More information about the Tutor