PEP ? os.listdir enhancement

Thomas Guettler guettli at thomas-guettler.de
Thu Jun 23 10:45:16 EDT 2005


Am Wed, 22 Jun 2005 17:57:14 +0200 schrieb Riccardo Galli:

> Hi,
> I noticed that when I use os.listdir I need to work with absolute paths
> 90% of times.
> While I can use a for cycle, I'd prefere to use a list comprehension,
>  but it becomes too long.

Hi,

I like it. But as you noticed, too, "join" would be better than "abs".

Example:

# mylistdir.py
import os
import sys

def mylistdir(dir, join=False):
    for file in os.listdir(dir):
        yield os.path.join(dir, file)


print list(mylistdir(sys.argv[1]))


 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list