Lawrence D'Oliveiro <[EMAIL PROTECTED]> wrote: > for \ > Entry \ > in \ > sorted \ > ( > f for f in os.listdir(PatchesDir) if > PatchDatePat.search(f) != None > ) \ >: > Patch = (open, > gzip.GzipFile)[Entry.endswith(".gz")](os.path.join(PatchesDir, > Entry), "r") ... read from Patch ... > Patch.close() > #end for >
Have you ever considered trying to write readable code instead? Something like (untested): def patchfiles(dir, pattern): for f in os.listdir(dir): if pat.search(f) is not None: yield os.path.join(dir, f) def openpatch(name): if name.endswith(".gz"): return gzip.GzipFile(name, "r") return open(name, "r") for entry in sorted(patchfiles(PatchesDir, PatchDatePat): with openpatch(entry) as patch: ... read from patch ... (I must admit I haven't checked whether GZipFile works with the 'with' statement, but if it doesn't you just wrap it in contextlib.closing). -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list