Don't you just love writing this sort of thing :)
Harold Fellermann
dadapapa at googlemail.com
Thu Dec 4 06:24:42 EST 2008
On Dec 4, 10:39 am, Cong Ma <c... at mail.bnu.edu.cn> wrote:
> Lawrence D'Oliveiro 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
>
> The "if ... != None" is not necessary... "if PatchDatePat.search(f)" is OK.
> And I don't like it...
Maybe the whole if clause is not necessary? This is how I would try
it:
for Entry in filter(PatchDatePat.search, os.listdir(PatchesDir)) :
fname = os.path(PatchesDir, Entry)
Patch = file(fname) if fname.endswith('.gz') else GzipFile(fname)
# ... read from Patch ...
Patch.close()
More information about the Python-list
mailing list