How can I get the names of the files in a directory?

Stian Soiland stian at soiland.no
Sun Jan 16 18:32:35 CET 2005


På 15. jan 2005 kl. 16:16 skrev .removethis.:

> >>> import glob
> >>> from os.path import isfile
> >>> print filter(isfile, glob.glob('/tmp/*')) # can use patterns

Nice example of when filter() is better than list comprehension.

[f for f in glob.glob("/tmp/*") if isfile(fi)]
is a bit too verbose, the iteration is a totally uninteresting part 
here.

-- 
Stian Søiland
Trondheim, Norway
http://www.soiland.no/
                      =/\=




More information about the Python-list mailing list