Is pyton for me?

Kirk Job Sluder kirk at jobsluder.net
Sat Jun 11 00:33:07 EDT 2005


Mike Meyer <mwm at mired.org> writes:

> "Mark de+la+Fuente" <dela_f at excite.com> writes:
> 
> > I need to write simple scripts for executing command line functions.
> > Up till now I've used C-Shell scripts for this, but I'm looking for
> > a better alternative.  And I keep reading about how “easy” it is to
> > program with python.
> 
> As others pointed out, Python isn't a shell, or even a shell scripting
> language, so it doesn't handle what you're doing in a "natural"
> way. Because of that, it may not be the language for you. Python has
> features that work well for building large systems, but those tend to
> cause extra work when you want to do things that other languages make
> simple.

I agree with this approach.  For me, there has to be a certain level of
complexity before I reach for python as a tool.  This usually involves
one or more of the following:

1: text processing involving multiple files. For example, running
statistics on file A, looking up values stored in file B.

2: cases where the overhead of repeatedly opening processes and pipes
becomes unacceptable.
For example:
for f in file/*; do
        cp $f $f.bak
        sed -e 'something' < $f.bak > $f
done

This works well with small numbers of files.  But even though sed is
quicker than python, starting a new sed process with every iteration
quickly stacks up.  Rewriting the entire thing to run as a single
process can dramatically improve performance.  Although this might be a
case of premature optimization.

3: cases where figuring out how to do something using one of the POSIX
shell utilities makes my head hurt.  

Personally, I hate popen and avoid using it when possible.  There is
nothing wrong with sh as a glue language when all you need is something
like: grep text file | filter | filter > output_file.  



>     <mike
> -- 
> Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

-- 
Kirk Job-Sluder
"The square-jawed homunculi of Tommy Hilfinger ads make every day an
existential holocaust."  --Scary Go Round



More information about the Python-list mailing list