How to stop python recursion -
i made function searches files recursively , want stop recursion when first file found:
def search_file(path): name in os.listdir(path): sub = os.path.join(path, name) if os.path.isfile(sub): return sub#and break recursion else: search_file(sub)
return flag says whether file found. when call search_file
, return if return value true.
Comments
Post a Comment