[Python-ideas] Make Path objects iterable

Philipp A. flying-sheep at web.de
Mon Feb 27 03:32:02 EST 2017


<devils-advocate>
the same is true for files: Deciding to iterate them line-wise is
relatively arbitrary, byte/char-wise would be equally intitive. So
something could be chosen.
</devils-advocate>

But I think being explicit in the case of paths is really not that
inconvenient.

Serhiy Storchaka <storchaka at gmail.com> schrieb am So., 26. Feb. 2017 um
16:14 Uhr:

On 26.02.17 15:39, Vamsi Krishna Avula wrote:
> This is somewhere between a question and a proposal. I'm just trying to
understand why Path objects use an explicit iterdir method.
> Why not make them iterable?

Because this is ambiguous. Iterating can mean many different things:

1. Iterate characters of string representation of the path (str(path)).

2. Iterate path components (path.parts).

3. Open a file and iterate its lines (path.open()).

4. Iterate files in the directory (path.iterdir()).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170227/98fcad0e/attachment.html>


More information about the Python-ideas mailing list