Re: [Python-ideas] pathlib.Path.walk
On Mon, Apr 3, 2017 at 5:33 PM, Michel Desmoulinwrote: > Like os.walk, but from a Path instance. > > We have Path.iterdir, but it's not recursive. Which you use either > os.scandir, or os.walk. In any case, you end up doing: > > import os > import pathlib > > directory = pathlib.Path(get_dir()) > > # do things with directory > > for root, dirs, files os.walk(directory): > root = Path(root) > for f in files: > f = root / f > # do something with file > > Which is not that bad, but you waste a lot of time discovering how to do > that since you look first for something like Path.walk. > OK, but what Path.walk should be return? If all of dirs and files are Path object, it will have significant performance overhead. for root, dirs, files in directory.walk(): # all dirs are path object, but not used. for f in files: f = root / f # And Path overhead can be avoided for files too. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] pathlib.Path.walk
Why not Path.glob? https://docs.python.org/3.6/library/pathlib.html#pathlib.Path.glob On Mon, Apr 3, 2017 at 5:33 PM, Michel Desmoulinwrote: > Like os.walk, but from a Path instance. > > We have Path.iterdir, but it's not recursive. Which you use either > os.scandir, or os.walk. In any case, you end up doing: > > import os > import pathlib > > directory = pathlib.Path(get_dir()) > > # do things with directory > > for root, dirs, files os.walk(directory): > root = Path(root) > for f in files: > f = root / f > # do something with file > > Which is not that bad, but you waste a lot of time discovering how to do > that since you look first for something like Path.walk. > > ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] pathlib.Path.walk
Like os.walk, but from a Path instance. We have Path.iterdir, but it's not recursive. Which you use either os.scandir, or os.walk. In any case, you end up doing: import os import pathlib directory = pathlib.Path(get_dir()) # do things with directory for root, dirs, files os.walk(directory): root = Path(root) for f in files: f = root / f # do something with file Which is not that bad, but you waste a lot of time discovering how to do that since you look first for something like Path.walk. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/