Use Python for Scripting

38 points by hyPiRion


koala

Bash is my favorite programming language, but lately I write any non-trivial script in Python.

My main annoyance is that all my scripts start with a wrapper for subprocess.run that sets check=True by default and prints out the command to be run with shlex.join. This function grows a few more functionalities depending on the script.

Another annoyance is that I have not found an equivalent I like for Bash's exec.

But pathlib.Path.(read|write)_(text|bytes), f-strings, tempfile.NamedTemporaryFile(delete_on_close=False) (very recent, I was basically using temporary directories for everything normally), textwrap.dedent with multiline strings, built-in json, tarfile, argparse, getpass, concurrent.futures' map, context managers... are very useful batteries without resorting to dependencies.

It's still not entirely mainstream to have tools that allow embedded dependencies, but at some point we'll get there, I guess.