I’d like to propose an enhancement to the wonderful pathlib module: make Path instances iterable, where the iterator returns subpaths.
This would be functionally very similar to Path(some_directory).rglob(‘*’). Why not just use rglob(‘*’)? While globs are an extremely useful shorthand, in my experience they’re a bit of an artifact of Unix shells that programmers frequently aren’t aware of or don’t understand. Python does a great job of distilling the concept of what it means to iterate over an object. IO objects come to mind, where [line for line in sys.stdin] very intuitively iterates through each line of input. I believe making Path iterable over its sub paths provides a similarly intuitive concept of iterating over a path. Strawman implementation: class Path: # ... def __iter__(self): return self.rglob('*') Questions: If this were added, where in the Path class hierarchy[1] would it belong? [1]: https://docs.python.org/3/library/pathlib.html#module-pathlib
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7LWJXZ5OIAYZEZJUVWGHCASFCQPAOJIK/ Code of Conduct: http://python.org/psf/codeofconduct/