os.walk question

Fredrik Lundh fredrik at pythonware.com
Wed Jul 23 08:26:39 EDT 2008


alex23 wrote:

>> if you want a list of files from a single directory, use listdir, not walk:
>>
>>       >>> import os, random
>>       >>> random.choice(os.listdir("/"))
>>       'python25'
> 
> This will include folders as well, though, which isn't what the OP
> asked for.

as illustrated by my example (cut and pasted from a windows machine).  oops.

     random.choice(filter(os.path.isfile, glob.glob("/*")))

isn't that bad, though.

</F>




More information about the Python-list mailing list