scanf style parsing

Tim Hammerquist tim at vegeta.ath.cx
Fri Sep 28 17:59:43 EDT 2001


Me parece que Stefan Schwarzer <s.schwarzer at ndh.net> dijo:
> Hi Tim
> 
> my posting is not really related to the scanf discussion but maybe helpful ...
> 
> Tim Hammerquist wrote:
> > or, much more preferably:
> > 
> >     if filename[-4:] == '.txt':
> >         ...
> 
> Since (I think:) Python 2.0 it's possible to use
> 
> if filename.endswith('.txt'):
>     ...
> 
> which is less error-prone if the string is a bit longer.

..and much more maintainable. You no longer must change the index when
the length of the string changes.  Very nice.  I hadn't been
familiarized with this method.  Thank you for bringing it up.

> Stefan

Tim Hammerquist
-- 
I would feel infinitely more comfortable in your presence if you would agree
to treat Gravity as a Law, rather than one of a number suggested options.
    -- Barnabas, The Sandman



More information about the Python-list mailing list