String compare question

Robert Dailey rcdailey at gmail.com
Mon Feb 25 16:20:08 EST 2008


Thanks for your help. I knew of a way to solve this issue, but being a C++
programmer I tend to think of the expanded solutions for things. I wasn't
sure if there was a more compact solution for python. Thanks again!

On Mon, Feb 25, 2008 at 11:27 AM, Tim Chase <python.list at tim.thechases.com>
wrote:

> >> ignored_dirs = (
> >>    r".\boost\include",  # It's that comma that makes this a tuple.
> >>     )
> >>
> >
> > Thanks for reminding me of this. I always forget that!
> >
> > Now that it is correctly doing *only* whole string matches, what if I
> want
> > to make it do a substring compare to each string in my ignored_dirs
> tuple?
>
> Sounds like a good opportunity for the underused for/break/else
> construct:
>
> ######################################################
> ignored_dirs = (
>     r".\boost\include",
>      )
>
> if __name__ == "__main__":
>     # Walk the directory tree rooted at 'source'
>     for root, dirs, files in os.walk( source ):
>         for dirname in ignored_dirs:
>             # may need to normalize to root.lower()
>             if dirname in root:
>                 print 'Skipping', root
>                 break
>         else:
>             CopyFiles( root, files, ".dll" )
> ######################################################
>
> -tkc
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080225/37262fb3/attachment-0001.html>


More information about the Python-list mailing list