Skip to content

Instantly share code, notes, and snippets.

@mattgathu
Created July 22, 2015 06:27
Show Gist options
  • Save mattgathu/9e5523b9f739a675afd1 to your computer and use it in GitHub Desktop.
Save mattgathu/9e5523b9f739a675afd1 to your computer and use it in GitHub Desktop.
Python logs file names and contents generators
def gen_log_files():
"""Generate log files names"""
for root, _, files in os.walk(DEFAULT_LOG_DIR):
for name in files:
if is_pref_file(name):
yield os.path.join(root, name)
def gen_contents(fnames):
"""Generate file contents
"""
for name in fnames:
try:
yield name, open(name, 'r').read()
except UnicodeDecodeError:
continue
except IOError as err:
if err.errno == EACCES:
continue
else:
raise err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment