[Tutor] Regex's and "best practice"
littledanehren at yahoo.com
Sun Nov 23 14:32:50 EST 2003
Carl D Cravens wrote:
> On Sat, 22 Nov 2003, Gerrit Holl wrote:
> > You may want to use an entirely different approach
> to the problem.
> > You don't need regular expressions at all. A
> number of high-level
> > libraries are available for this problem: the
> mailbox module,
> > the email module, e.g.
> Yes, but that avoids the point of the exercise... to
> convert one of my
> Perl scripts to Python to see how they compare.
> I wrote the original script back in '86 on Perl 4.
> I don't think there
> were any public mail libraries (modules didn't exist
> with Perl 4) at the
> time, or I'd have just taken that approach with the
> Perl script as well.
> > What you are doing, is translating Perl to Python.
> But it doesn't become
> > Python then, it becomes translated Perl.
> Which was the point of my original post... to see if
> I was missing
> something obvious to the experienced Python coder.
> But let's drop down a level and say I'm writing a
> mailbox module. I'd
> probably still be using regexes, because trying to
> extract what I'm
> looking for without them would be rather tedious.
> Carl D Cravens (raven at phoenyx.net)
> Dogs crawl under fences, Software crawls under
There is a major difference in the philosophies of
Perl and Python. Among other things, the Pearl doesn't
have nearly as many standard libraries as Python does
because they believe that things should be in
seperate, user-made libraries, or just reimplimented
in the individual program. With Python, unless you
have a specific goal of creating a faster library or
something (in which case you'd probably use C anyway),
it really doesn't make sense to reimpliment things.
The availability of these libraries should be taken
into account when considering how easy it would be to
make one of these programs. If there is no similar
library in Perl, that doesn't mean you should write
the Python program poorly.
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
More information about the Tutor