Opinion on best practice...

Michael Torrie torriem at gmail.com
Wed Feb 6 00:07:33 EST 2013


On 02/05/2013 08:32 PM, Nobody wrote:
> A shell script is only the better option if (almost) the *only* thing the
> script needs to do is to execute commands.
> 
> The moment you start trying to "process" data, it's time to put up with
> the verbosity of subprocess.Popen() so that you can use a well-designed
> language for the rest of it.

Agreed.  And most of the time a script in bash is going to do something
like:

grep blah /from/file | cut -f 1 -d ' ' | uniq | sort

Python generators happen to be very efficient at recreating this sort of
thing entirely in python.  A great presentation that all system
programmers should read is found here:

http://www.dabeaz.com/generators/

Very cool stuff.  Grep is just a generator function.  cut is just a
generator function, and so on.  And it can be pretty darn fast too.



More information about the Python-list mailing list