ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: scanf style parsing
by Andrei Kulakov other posts by this author
Sep 27 2001 5:53PM messages near this date
Re: scanf style parsing | Re: scanf style parsing
On Thu, 27 Sep 2001 11:32:35 +0000 (UTC), Duncan Booth <duncan@[...].uk>  wrote:
>  tim@[...].cx (Tim Hammerquist) wrote in 
>  news:slrn9r61oo.uim.tim@vegeta.ath.cx:
>  
> > But don't think regex's are disposable just because Python's string type
> > is more convenient.  Consider the following:
> > 
> >     # perl
> >     if ($filename =~ /\.([ps]?html?|cgi|php[\d]?|pl)$/) { ... }
> >     # python
> >     re_web_files = re.compile(r'\.([ps]?html?|cgi|php[\d]?|pl)$')
> >     m = re_web_files.search(filename)
> >     if m:
> >         ...
> > 
> > This is a very complicated (but relatively efficient way) to match files
> > with all the folowing extensions:
> >     .htm    .html   .shtm   .shtml  .phtm   .phtml
> >     .cgi
> >     .php    .php2   .php3   .php4
> >     .pl
>  
>  Wouldn't you be happier with this?:
>  
>     extensions = ['.htm', '.html', '.shtm', '.shtml', '.phtm',
>          '.phtml', '.cgi', '.php', '.php2', 'php3', '.php4', '.pl']
>     ext = os.path.splitext(filename)[1]
>     if ext in extensions:
It would be even better to:
     if ext.lower() in extensions:

>        ...
>  
>  which has the arguable advantage of matching what your description says 
>  instead of what your original code does.
>  
>  regexes are wonderful: in moderation.

I hate them! :/

>  


-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org
-- 
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved