breaking from loop

George Sakkis george.sakkis at gmail.com
Fri Feb 10 21:11:16 EST 2006


Using the (non-standard yet) path module
(http://www.jorendorff.com/articles/python/path/), your code can be
simplified to:

from path import path, copy

def copy_first_match(repository, filename, dest_dir):
    try:
        first_match = path(repository).walkfiles(filename).next()
    except StopIteration:
        return False
    else:
        copy(first_match, dest_dir)
        return True


I/O exceptions are left to propagate to the caller.

George




More information about the Python-list mailing list