On Jul 23, 5:22 pm, Fredrik Lundh <[EMAIL PROTECTED]> 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. >>> import os, random >>> root = "/" >>> random.choice([f for f in os.listdir(root) if >>> os.path.isfile(os.path.join(root, f))]) 'initrd.img' It just seems clunky compared to os.walk :) -- http://mail.python.org/mailman/listinfo/python-list