Based on feedback from people annoyed at having to write "comprehensions
and generator expressions" to refer to what ought to be a single concept,
Guido has given the thumbs up for a documentation change to start
referring to "generator comprehensions".
https://mail.
Caleb Hattingh wrote:
Would
filenames = [os.path.join(dirpath, filename)
for dirpath, dirnames, filenames in os.walk('.')
for filename in filenames]
have been clearer for you? Then all you have to do is remember the
order of the for-loop execution:
Bizarr
Wow, Steve, thanks, you went to some effort here.
I prefer to give names to the values produced by os.walk -- I think it
makes the usage much clearer. However, since I don't use 'dirnames', I
use '_' to indicate this:
Actually, I feel silly for not recognising this - I read about the Python3
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
at the OP's original code, the line:
[(x[0], x[2]) for x in os.walk(".")]
is the equivalent of:
[dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')]
Just a nit: you need parentheses in your second LC too, i.e.:
[(dir
Steven Bethard <[EMAIL PROTECTED]> wrote:
> at the OP's original code, the line:
>
> [(x[0], x[2]) for x in os.walk(".")]
>
> is the equivalent of:
>
> [dirpath, filenames for dirpath, dirnames, filenames in os.walk('.')]
Just a nit: you need parentheses in your second LC too, i.e.:
[(dirp
Caleb Hattingh wrote:
filenames = [os.path.join(dirpath, filename)
# This is cool
for dirpath, _, filenames in os.walk('.')
# This is getting tricky, whats the '_' for?
Nothing to do with the list comprehension really. '_' is a commonly
used variable name
Sure Steve
Lemme see ... (indentation changed so comments associate with correct bits)
Out of curiosity, do you find:
filenames = [os.path.join(dirpath, filename)
# This is cool
for dirpath, _, filenames in os.walk('.')
# This is getting tricky, whats
On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote:
>
> walkList = [(x[0], x[2]) for x in os.walk(".")]
> filenames = []
> for dir, files in walkList:
> filenames.extend(["/".join([dir, f]) for f in files])
Caleb Hattingh top-posted:
I would be interested to see an example
> HTH,
It does. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
I would be interested to see an example of code that is more concise but
yet as *clear* as the one you already have. I can actually read and
understand what you've got there. That's cool :)
On 6 Feb 2005 11:28:37 -0800, <[EMAIL PROTECTED]> wrote:
I wrote this little piece of code to get a l
[EMAIL PROTECTED] wrote:
I wrote this little piece of code to get a list of relative paths of
all files in or below the current directory (*NIX):
walkList = [(x[0], x[2]) for x in os.walk(".")]
filenames = []
for dir, files in walkList:
filenames.extend(["/".join([dir, f]) for
I wrote this little piece of code to get a list of relative paths of
all files in or below the current directory (*NIX):
walkList = [(x[0], x[2]) for x in os.walk(".")]
filenames = []
for dir, files in walkList:
filenames.extend(["/".join([dir, f]) for f in files])
It works f
12 matches
Mail list logo