DragonFly kernel List (threaded) for 2008-02
DragonFly BSD
DragonFly kernel List (threaded) for 2008-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Globbing


From: Rahul Siddharthan <rsidd120@xxxxxxxxx>
Date: 14 Feb 2008 17:17:40 GMT
Keywords:
Summary:

Oliver Fromme wrote:
> > This would be the Python way to do it, just for the record:
> >
> > [x for x in listdir(".") if exists(x + "c")]
>
>Uhm, I'm sorry, the question was to find those files for
>which there is _no_ .elc file.  So there's a negation
>missing:
>
>[x for x in listdir(".") if not exists(x + "c")]

Actually you only want .el files that lack .elc files.  So it would be
  [x for x in listdir(".") if x[-3:]==".el" and not exists(x + "c")]

But the question was to find such all such files in a directory tree,
not just in the current directory.  I don't know whether there is a
python builtin for recursive directory listings, but it is trivial to
write one, so the above would work for that too.

(also, exists should be path.exists or os.path.exists depending on how
os was imported.  But it seems wasteful to use it since we only need
the directory listing.  I'd store the directory listing in a separate
variable and check for existence in that.)

I did say I'd do it in python, and list comprehensions are the number
two reason why I like python.  The overall clean syntax is the number
one reason.

Rahul



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]