[issue46227] add pathlib.Path.walk method

2022-01-08 Thread Stanislav Zmiev


Stanislav Zmiev  added the comment:

Thanks for the tip! Hopefully, I created it correctly:
https://discuss.python.org/t/add-pathlib-path-walk-method/

It is currently on review.

--

___
Python tracker 
<https://bugs.python.org/issue46227>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46227] add pathlib.Path.walk method

2022-01-02 Thread Stanislav Zmiev


Change by Stanislav Zmiev :


--
keywords: +patch
pull_requests: +28552
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30340

___
Python tracker 
<https://bugs.python.org/issue46227>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46227] add pathlib.Path.walk method

2022-01-02 Thread Stanislav Zmiev


Stanislav Zmiev  added the comment:

Some people could suggest using Path.glob instead but I found it to be less 
convenient for some use cases and generally slower (~2.7 times slower).

>>> timeit("list(Path('Lib').walk())", number=100, globals=globals())
1.9074640140170231
>>> timeit("list(Path('Lib').glob('**/*'))", number=100, globals=globals())
5.14890358998673

--

___
Python tracker 
<https://bugs.python.org/issue46227>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46227] add pathlib.Path.walk method

2022-01-02 Thread Stanislav Zmiev


New submission from Stanislav Zmiev :

Pathlib is great, yet every time I have to parse a bunch of files, I have to 
use os.walk and join paths by hand. That's not a lot of code but I feel like 
pathlib should have higher-level abstractions for all path-related 
functionality of os. I propose we add a Path.walk method that could look like 
this:

def walk(self, topdown=True, onerror=None, followlinks=False):
for root, dirs, files in self._accessor.walk(
self,
topdown=topdown,
onerror=onerror,
followlinks=followlinks
):
root_path = Path(root)
yield (
root_path,
[root_path._make_child_relpath(dir_) for dir_ in dirs],
[root_path._make_child_relpath(file) for file in files],
)


Note: this version does not handle a situation when top does not exist (similar 
to os.walk that also doesn't handle it and just returns an empty generator)

--
components: Library (Lib)
messages: 409511
nosy: Ovsyanka
priority: normal
severity: normal
status: open
title: add pathlib.Path.walk method
type: enhancement
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue46227>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com