3 ms·
yeah exactly. eg find . -type f | grep foo is possible to do with os.walk() in python, but to get there is so unergonomic.
by fragmede 3y ago
yeah exactly.
eg
find . -type f | grep foo
is possible to do with os.walk() in python, but to get there is so unergonomic.
- vlovich123 3y agofor file_path in sh.find(".", "-type", "f", _iter=True): if "foo" in file_path: print(file_path) Note that "find" is not some special function provided by the sh module - that module just uses convenience magic where it'll map whatever function you call under it as an actual command execution (i.e. construct a sh.Command using "find" as an argument & then execute it). You can also pipe the output of find to grep if you want to run grep for some reason instead of writing that processing in python (maybe it's faster or just more convenient)