scanf style parsing
Malcolm Tredinnick
malcolm at commsecure.com.au
Sat Sep 29 12:19:41 EDT 2001
More information about the Python-list mailing list
Sat Sep 29 12:19:41 EDT 2001
- Previous message (by thread): scanf style parsing
- Next message (by thread): scanf style parsing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Sep 29, 2001 at 03:47:49PM +0000, chasm at atlantis.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.
- Previous message (by thread): scanf style parsing
- Next message (by thread): scanf style parsing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list