sure, but having to write "little" wrappers for common needs is unfortunate...You're replying to me, not Guido, here...
Anyway, if the only thing anyone will ever need is a handful of simple one-liners that even a novice could write, maybe it's reasonable to just add one to the docs to show how to do it, instead of adding them to the stdlib.
The problem isn't designing a nice walk API; it's integrating it with pathlib.*indeed -- I'd really like to see a *walk in pathlib itself.
I've been trying to use pathlib whenever I need, well, a path, but then I find I almost immediately need to step out and use an os.path function, and have to string-fy it anyway -- makes me wonder what the point is..
And honestly, if open, os.walk, etc. aren't going to work with Path objects,but they should -- of course they should.....
My example: one of our sysadmins wanted a little script to go thorugh an entire drive (Windows), and check if any paths were longer than 256 characters (Windows, remember..)I came up with this:def get_all_paths(start_dir='/'):for dirpath, dirnames, filenames in os.walk(start_dir):for filename in filenames:yield os.path.join(dirpath, filename)too_long = for p in get_all_paths('/'):print("checking:", p)if len(p) > 255:too_long.append(p)print("Path too long!")
way too wordy!I started with pathlib, but that just made it worse.
As a side note, there's no Windows restriction to 255 _characters_, it's to 255 UTF-16 code points,
just under 64K UTF-16 code points,
or 255 codepage bytes, depending on which API you use.
So you really want something like len(file.encode('utf-16') / 2) > 255.
Also, I suspect you want either the bare filename or the abspath, not the path from the start dir (especially since a path rooted at the default '/' is two characters shorter than one rooted at 'C:\',