Plumbum: Pythonic Shell Combinators
github.com
github.com
(sudo[ifconfig["-a"]] | grep["-i", "loop"]) & FG
is more readable than sudo ifconfig -a | grep -i loop &- Ability to leverage the richness of Python to pre/post-process the inputs/outputs from other shell commands.
- Easier to parameterise and maintain.
- Familiarity with Python over the likes of bash, zsh, etc.
local("ls - l | grep foo")
If you want to use Python to manipulate the input or output of shell commands, then write a Python script that reads from stdin and writes to stdout, and use the shell to insert that script into the appropriate point in your command chain. It's the UNIX way.
Not to say being pythonic is always better, but some of these tricks don't even seem that practical. Why "& FG" instead of .fg()? Using division for joining paths is cute, but why not use '+', the conventional append operator?
content = commands.getoutput(x)
is much better than os.system(x + ' > foo')
content = open('foo', 'r').read() content = subprocess.check_output(x, shell=True)