You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importosimportfnmatchimportgzipimportbz2importredefgen_find(filepat, top):
''' Find all filenames in a directory tree that match a shell wildcard pattern '''forpath, dirlist, filelistinos.walk(top):
fornameinfnmatch.filter(filelist, filepat):
yieldos.path.join(path,name)
defgen_opener(filenames):
''' Open a sequence of filenames one at a time producing a file object. The file is closed immediately when proceeding to the next iteration. '''forfilenameinfilenames:
iffilename.endswith('.gz'):
f=gzip.open(filename, 'rt')
eliffilename.endswith('.bz2'):
f=bz2.open(filename, 'rt')
else:
f=open(filename, 'rt')
yieldff.close()
defgen_concatenate(iterators):
''' Chain a sequence of iterators together into a single sequence. '''foritiniterators:
yieldfromitdefgen_grep(pattern, lines):
''' Look for a regex pattern in a sequence of lines '''pat=re.compile(pattern)
forlineinlines:
ifpat.search(line):
yieldline
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: