script files with python (instead of tcsh/bash)?

D'Arcy J.M. Cain darcy at
Sat Mar 21 15:56:41 CET 2009

On Sat, 21 Mar 2009 09:26:02 -0400
Esmail <ebonak at> wrote:
> Hello all,
> I am wondering if anyone is using python to write script files?

All the time.

> Right now I have a bigg'ish bash/tcsh script that contain some grep/awk
> command plus various files are processed and created, renamed and
> moved to specific directories. I also write out some gnuplot scripts
> that later get executed to generate .jpg images.
> In any case, the scripts are starting to look pretty hairy and I was
> wondering if it would make sense to re-write them in Python. I am not
> sure how suitable it would be for this.

Your message is a little confused.  In one paragraph you appear to be
talking about one specific script and the next you are talking about
more than one.  Regardless, I will try to give some generic advice.

First, have a toolbox.  No carpenter goes to work with just a hammer.
Sometimes he needs a screwdriver and more than one type at that.  Try
to be comfortable with all of your tools.  Once you reach that point
you should have no problem figuring out which tool you need for any
specific job.

Sometimes the answer is Perl, sed, awk or some other tool, perhaps a
specialized one that you wrote. OK, maybe it's never Perl.  :-)

Naturally you can use popen and system to convert any shell script into
Python but if your Python script is overflowing with those calls then
you need to either refactor your code to use Python directly or stay
with the shell script.

There's nothing that says that you need to use one and only one tool
for any particular job.  I have many times written shell scripts that
call Python (either by script or command line) to do things that are
easier in Python.  Yesterday I did the opposite.  I had a shell script
that generated some data and I used a Python script to popen it and
work with the information.

After all that, if you really do feel that you need to focus on one
tool I suppose you could do worse than choosing Python as your hammer.

> I've looked around the web w/o much luck for some examples but come
> short. Any comments/suggestions?

I think that the reason for that is that most people aren't so
concerned with conversion.  If the shell script works, why bother?
They will just pick the best tool for their next project.

D'Arcy J.M. Cain <darcy at>         |  Democracy is three wolves                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

More information about the Python-list mailing list