Is this a dream or a nightmare? (Was Re: XML)

Grant Griffin g2 at seebelow.org
Sun Oct 8 05:09:36 EDT 2000


Tim Peters wrote:
> 
> [David T. Grove]
> > die unless @d = map {"$basedir/$_"} grep {!-d && -w} readdir(dir);
> 
> [Grant Griffin]
> > What in the heck does all _that_ mean?
> 
> [back to David]
> > Actually, fully extended, it means "give me a platform independent
> > list of writable (non-directory) files in that directory in a form
> > that will allow me to name the files so that I can see them from
> > elsewhere in my code regardless of where they are on disk, or halt
> > immediately because if this doesn't work you might screw something
> > up".
...
> Python (2.0) code for doing all that correctly is no more lines (it could be
> squashed into fewer but not profitably), but they are longer; OTOH, they do
> more, and don't change the current directory:
> 
> import os, stat
> basedir = os.path.normpath("/code")
> paths = [os.path.join(basedir, f) for f in os.listdir(basedir)]
> d = [p for p in paths if os.path.isfile(p)
>                       if os.stat(p)[stat.ST_MODE] & 0222]

Hey, waitaminute!  It this a case where the Python code is actually
_smaller_ than the "natural language" equivalent above?

maybe-guido-is-secretly-a-linguist-like-larry-wall-<wink>-ly y'rs,

=g2
-- 
_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation	      http://www.iowegian.com



More information about the Python-list mailing list