Krishna Bharadwaj krishna.bm...@gmail.com added the comment:
Have included a patch which alters the walk method to yield a namedtuple and
the members can be accessed by dirpath, dirnames and filenames.
Got the following results after running the test.
Ran 61 tests in 0.080s
OK (skipped=4)
Amaury Forgeot d'Arc amaur...@gmail.com added the comment:
This patch needs a test at least.
Also, the walktuple type should be defined only once, at the module level
(but then, there may be a boostrap issue, I don't know).
--
nosy: +amaury.forgeotdarc
Krishna Bharadwaj krishna.bm...@gmail.com added the comment:
Hey Amaury,
can you tell me if the following test cases would suffice? If not, I can think
of adding something more comprehensive. Also, can you provide some pointers
related to the bootstrap issue so that I can look at the same?
Benjamin Peterson benja...@python.org added the comment:
Perhaps Raymond has a different view, but I don't this patch makes anything
more clear. There's only three things to remember and its convenient to unpack
it in the loop like
for path, dirs, files in os.walk(somewhere):
...
Nick Coghlan ncogh...@gmail.com added the comment:
Like any named tuple, the benefits lie in the better repr, and the fact
that if you only want some fields you don't have to unpack the whole tuple.
It's also easier to write variant APIs that add additional fields
accessible only by name.
Antoine Pitrou pit...@free.fr added the comment:
Like any named tuple, the benefits lie in the better repr, and the fact
that if you only want some fields you don't have to unpack the whole
tuple.
But, given the common idiom shown by Benjamin, how likely is it that you
manipulate the tuple
Nick Coghlan ncogh...@gmail.com added the comment:
Why provide any namedtuple interface in any context? After all, you can just
unpack them to individual variables.
The point is that the values produced by os.walk() *aren't* just an arbitrary
3-tuple - they have a definite API for describing
Benjamin Peterson benja...@python.org added the comment:
2011/11/9 Nick Coghlan rep...@bugs.python.org:
Nick Coghlan ncogh...@gmail.com added the comment:
Why provide any namedtuple interface in any context? After all, you can just
unpack them to individual variables.
The point is that
Nick Coghlan ncogh...@gmail.com added the comment:
I'm persuaded that there's no major gain to be had in building this in at the
base layer - it's easy enough to add in a higher level API.
--
resolution: - rejected
status: open - closed
___
Python
New submission from Nick Coghlan ncogh...@gmail.com:
The 3-tuple values yielded by os.walk could be made easier to work with in some
use cases by offering a namedtuple style interface (similar to what is done
with sys.float_info).
for dirinfo in os.walk(base_dir):
print(dirinfo.path)
Changes by Nick Coghlan ncogh...@gmail.com:
--
stage: - needs patch
type: - feature request
versions: +Python 3.3
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13375
___
11 matches
Mail list logo