Re: os.walk question

2008-07-26 Thread Eric Wertman
I do this, mabye a no-no? import os for root,dirs,files in os.walk(dir) : break -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-26 Thread Terry Reedy
Eric Wertman wrote: I do this, mabye a no-no? It is a roundabout way to do multiple assignment: import os for root,dirs,files in os.walk(dir) : break root,dirs,files = os.walk(dir).next #2.x root,dirs,files = next(os.walk(dir))#3.x --

Re: os.walk question

2008-07-25 Thread Fredrik Lundh
Lawrence D'Oliveiro wrote: Won't that return any subdirectories as well as files? sure, as was discussed in this very thread two days ago. /F -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-24 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Fredrik Lundh wrote: Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. if you want a list of files from a single directory, use listdir, not walk: import os,

os.walk question

2008-07-23 Thread Lanny
How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. Thanks. -- Posted on news://freenews.netfront.net - Complaints to [EMAIL PROTECTED] -- -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-23 Thread alex23
On Jul 24, 11:52 am, Lanny [EMAIL PROTECTED] wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. So you -only- want the files from one directory? Try: _, _, files = os.walk('/top/folder/here').next() The single

Re: os.walk question

2008-07-23 Thread Fredrik Lundh
Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. if you want a list of files from a single directory, use listdir, not walk: import os, random random.choice(os.listdir(/)) 'python25' /F --

Re: os.walk question

2008-07-23 Thread alex23
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.

Re: os.walk question

2008-07-23 Thread Larry Bates
Fredrik Lundh wrote: Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. if you want a list of files from a single directory, use listdir, not walk: import os, random random.choice(os.listdir(/))

Re: os.walk question

2008-07-23 Thread Fredrik Lundh
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

Re: os.walk question

2008-07-23 Thread alex23
On Jul 23, 10:11 pm, Larry Bates [EMAIL PROTECTED] wrote: import glob random.choice([f for f in glob.glob(root, *)]) glob.glob only accepts one argument though, did you mean root + *? It also returns folders as well as files, though, and the list comprehension is not necessary given it returns

Re: os.walk question

2008-07-23 Thread alex23
On Jul 23, 10:26 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:      random.choice(filter(os.path.isfile, glob.glob(/*))) isn't that bad, though. I'll agree to that. -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk question

2008-07-23 Thread B
Lanny wrote: How would one make a list of the files in the top directory using os.walk. I need to pick a random file from said list. Thanks. -- Posted on news://freenews.netfront.net - Complaints to [EMAIL PROTECTED] -- how about: import os x = os.walk('/') (root,dirs,files) =