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
--
http://mail.python.org/mailman/listinfo/python-lis
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
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.
--
http://mail.python.org/mailman/listinfo/python-list
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:
>
>
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) = x.next
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
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
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
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(
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 O
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'
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 singl
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
13 matches
Mail list logo