2 ms·
> But python is a bit fumbly when it comes to invoking external programs. try: ... subprocess.bleh except: ... ugh. I actually tend to prefer that these days —
by acdha 6y ago
> But python is a bit fumbly when it comes to invoking external programs. try: ... subprocess.bleh except: ... ugh.
I actually tend to prefer that these days — if I write shell I'm tossing in "set -e -u -o pipefail" anyway and subprocess's newer APIs end up being cleaner when you need to do anything non-trivial for error handling (I usually end up with one `try:` block for most of the program and maybe one or two `except: cleanup(); raise` blocks. Having the logic be clean and consistent saves you so much time when you revisit that program a month later.
The biggest wins I've seen from quoting external program arguments — either not needing to do so at all or passing things cleanly through shlex.quote makes it so much easier when you have the possibility of any special characters in arguments.