Michael Torrie <torr...@gmail.com> writes: > On 3/25/21 1:14 AM, Loris Bennett wrote: >> Does any one have a better approach? > > Not as such. Running a command and parsing its output is a relatively > common task. Years ago I wrote my own simple python wrapper function > that would make it easier to run a program with arguments, and capture > its output. I ended up using that wrapper many times, which saved a lot > of time. > > When it comes to converting a bash pipeline process to Python, it's > worth considering that most of pipelines seem to involve parsing using > sed or awk (as yours do), which is way easier to do from python without > that kind of pipelining. However there is a fantastic article I read > years ago about how generators are python's equivalent to a pipe. > Anyone wanting to replace a bash script with python should read this: > > https://www.dabeaz.com/generators/Generators.pdf
Thanks for the link - very instructive. > Also there's an interesting shell scripting language based on Python > called xonsh which makes it much easier to interact with processes like > bash does, but still leveraging Python to process the output. > https://xon.sh/ . That looks very interesting, too. Cheers, Loris -- This signature is currently under construction. -- https://mail.python.org/mailman/listinfo/python-list