Re: PEP ? os.listdir enhancement

2005-06-23 Thread Riccardo Galli
On Wed, 22 Jun 2005 11:27:06 -0500, Jeff Epler wrote: Why not just define the function yourself? Not every 3-line function needs to be built in. Of course I can code such a function, and I agree with the second sentence, but I think that obtaining absolutes path is a task so commonly needed

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Andreas Kostyrka
What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas On Thu, Jun 23, 2005 at 11:05:57AM +0200, Riccardo Galli wrote: On Wed, 22 Jun 2005 11:27:06 -0500, Jeff Epler wrote: Why not just define the function

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Konstantin Veretennicov
On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Riccardo Galli
On Thu, 23 Jun 2005 11:34:02 +0200, Andreas Kostyrka wrote: What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas how does it help in using list comprehension, as the ones in the first post? -- Riccardo

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Riccardo Galli
On Thu, 23 Jun 2005 12:56:08 +0300, Konstantin Veretennicov wrote: On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path',

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Daniel Dittmar
Riccardo Galli wrote: On Thu, 23 Jun 2005 12:56:08 +0300, Konstantin Veretennicov wrote: What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath on results? Should we add another keyword rel? Would it complicate listdir unnecessarily? keyword dir not exists (don't

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Peter Otten
Konstantin Veretennicov wrote: On 6/22/05, Riccardo Galli [EMAIL PROTECTED] wrote: I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a relative path. What about os.listdir(dir='relative/path', abs=True)? Should listdir call abspath

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Daniel Dittmar
Riccardo Galli wrote: On Thu, 23 Jun 2005 11:34:02 +0200, Andreas Kostyrka wrote: What's wrong with (os.path.join(d, x) for x in os.listdir(d)) It's short, and easier to understand then some obscure option ;) Andreas how does it help in using list comprehension, as the ones in the

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Riccardo Galli
On Thu, 23 Jun 2005 13:25:06 +0200, Daniel Dittmar wrote: He probably meant that a 'join' option would be more natural than an 'abs' option. After all, your examples use os.path.join to create a valid path that can be used as the argument to other module os functions. Whether the results are

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Thomas Guettler
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

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Ivan Van Laningham
Hi All-- Thomas Guettler wrote: 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

Re: PEP ? os.listdir enhancement

2005-06-23 Thread Riccardo Galli
On Thu, 23 Jun 2005 09:21:55 -0600, Ivan Van Laningham wrote: Mmmm, how about: # mylistdir.py import os, os.path import sys def mylistdir(dir, join=False): for file in os.listdir(dir): if join: yield join(dir, file) else: yield file print

PEP ? os.listdir enhancement

2005-06-22 Thread 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. I propose to add an 'abs' keyword which would make os.listdir return the absolute path of files instead of a

Re: PEP ? os.listdir enhancement

2005-06-22 Thread Jeff Epler
Why not just define the function yourself? Not every 3-line function needs to be built in. def listdir_joined(path): return [os.path.join(path, entry) for entry in os.listdir(path)] dirs = [x for x in listdir_joined(path) if os.path.isdir(x)] path_size = [(x, getsize(x)) for x in

Re: PEP ? os.listdir enhancement

2005-06-22 Thread Peter Hansen
Riccardo Galli wrote: 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. ### e.g. 1 part 1 - getting a list of directories ### dirs=[] for i in

Re: PEP ? os.listdir enhancement

2005-06-22 Thread Michael Hoffman
Peter Hansen wrote: Using Jason Orendorff's path module, all this code basically collapses down to this beauty (with your variable path renamed to myPath to avoid a name collision): This has to be the non-stdlib library I use the most. It's a great module. -- Michael Hoffman --