[Tutor] Python: 27 times faster than bash

Sean Carolan scarolan at gmail.com
Fri Oct 29 16:09:50 CEST 2010

> Can we see a version of your script?

How about just a couple snippets...there's no proprietary data but I
want to be on the safe side.  The original script consisted of a bunch
of functions similar to the one below.  When I first wrote this I
didn't know how to use sed very well, so I used variable substitution
to strip out the data I wanted:

So this function in bash:

function gettomcatserver ()
# Strip out the short hostname
       remoteserver=$(grep remote.server.host $adminfile)
       echo $remoteserver

Became this function in python:

def gettomcatserver( customername ):
   for line in open(adminfile).readlines():
       if line.startswith("remote.server.host="):
           return line.split("remote.server.host=")[1].split(".example.com")[0]

The total script runs several functions like this for each
$customername; I was quite impressed with the difference in speed.

More information about the Tutor mailing list