Re: scanf style parsing
by Malcolm Tredinnick other posts by this author
Sep 29 2001 4:19PM messages near this date
Re: scanf style parsing
|
Re: scanf style parsing
On Sat, Sep 29, 2001 at 03:47:49PM +0000, chasm@[...].rift wrote:
> >> Regex's are useful and powerful. But they're also very easy to
> >> abuse. I've actually seen the following Perl code:
> >>
> >> if ($filename =~ /\.txt$/) { ... }
> >>
> >> ...
> >>
> >> or, much more preferably:
> >>
> >> if filename[-4:] == '.txt':
> >
> >Overall, the Perl code's better. It didn't have to hard-code the
> >length of the string.
>
> ext = '.txt'
> if filename[-len(ext):] == ext:
>
> etc...
Or
if filename.endswith(ext):
# etc...
which is the reason the startswith() and endswith() string methods
exist. :-)
Cheers,
Malcolm
--
On the other hand, you have different fingers.
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
Bruce Dawson
Skip Montanaro
George Demmy
Hans-Peter Jansen
Quinn Dunkan
Tim Hammerquist
Ralph Corderoy
Toby Dickenson
Duncan Booth
Aahz Maruch
Aahz Maruch
Aahz Maruch
Stefan Schwarzer
Grant Edwards
Fredrik Lundh
Malcolm Tredinnick
Ralph Corderoy
Tim Hammerquist
Stefan Schwarzer
Greg Ewing
Skip Montanaro
Boyd Roberts
Steve Clift
Bruce Dawson
Tim Hammerquist
Tim Hammerquist
Tim Hammerquist
Skip Montanaro
Andrew Dalke
Fredrik Lundh
Oleg Broytmann
Andrei Kulakov
Duncan Booth
Chris Barker
Tim Hammerquist
Skip Montanaro
Jon Nicoll
Oleg Broytmann
Bruce Dawson
Skip Montanaro
Andrei Kulakov
Richard Jones
Skip Montanaro
Andrew Dalke
|