Python as a scripting language. Alternative to bash script?

Michael Torrie torriem at gmail.com
Mon Jun 28 17:18:41 EDT 2010


On 06/28/2010 02:06 PM, Mithrandir wrote:
> I can't see Python as an alt. to bash. (As I recall) Python is much more 
> object-oriented than bash, but also there are many commands (such as apt-
> get, etc.) that would need Python equivs. However, I can see Python being 
> used as a scripting alt. to C.

OO is a plus for most things, in my book.  As for "commands" they have
*nothing* to do with Bash.  apt-get is not a Bash command.  By your
logic tcsh or zsh would not be an alternate to bash, but in fact they are.

I use python for shell scripting quite often now.  Anytime one of my own
Bash scripts exceeds 100 lines, I know it's time to switch it to python.
 Please read that link I posted a while back on how you can use
generators in python to replace many of the things that piping to
external commands did in Bash.

There certainly are a few tasks that Bash is best at (chaining commands
together through pipes), but often Python already has support for many
of the things I'd use external commands and pipes in Bash for.  Bash is
designed for working down at the level of files, directories, and
processes, but Python works pretty well too, if you make some
abstraction modules like my runcmd module that I use extensively.



More information about the Python-list mailing list