def regex_findall(regex, fname): '''Return a list of all non overlapping matches in the string(s)''' try: with fileobj(fname) as f: return re.findall(regex, f.read(), re.MULTILINE) except AttributeError: return []