> From: Guido van Rossum <Guido.van.Rossum@cwi.nl>
> Regarding the future direction of Python: in my own use and that of
> colleagues I find that Python is used more as a replacement for C
> programs than as an improved perl or sh; interactive use tends to be
> fairly simple (e.g. testing code I've just written, or as a
> calculator). I couldn't do without interactive Python (nor with the
> command line editing) but I wouldn't use it to replace the shell
> either. What do other people use interactive Python for?
I use python for:
(1) Some of the usual sed/awk/perl type file munging.
For a while, perhaps, I was overdoing it at trying to use Python as
a replacement: I was in the middle of a ~10 line Python program when
I realized I could do the job with an awk one liner. On the other
hand, I often can't remember of get straight the proper escapes for
sed, so I used python yesterday to convert all of the carriage-returns
into line-feeds in a file. After '/015' and '/r' didn't work in sed,
it was easier to type a couple extra lines in python than dig out
the manual. If I was more of a wizzard at those other tools, I might
not use python, but python is easier to learn and remember, and
sometimes if I can't remember the name of a method, I can cheat and
type something like ".__methods__" or "dir(module)" and I don't
have to dig out the manual.
(2) System management "perl" type jobs. Generating disk usage reports, etc.
(3) Some iteractive shell type stuff where I'm not sure what I'm doing
when I start. I may want to recursivly build a list of files with
some defining criteria... and then when I discover that there are
"too many" , pare that list down by some other criterion , before
actually doing something with the list.
(4) Before I started to use GnuPlot, I used to use Python to read in
data files ( spectra ) and do some calculations on them ( difference
and normalizing ) and pipe them to "|plot |tek &". I had a 'plot'
routine that did a 'popen' and wrote out a list of numbers to the
pipe. With GnuPlot, I've just been putting the intermediate data
into a file. GnuPlot plots functions OR files BUT NOT functions OF
files, so I miss this. ( You can't say 'plot "data.1" - "data.2" '
for instance. ) I haven't looked into GnuPlot, so I don't know if
it would be easy to add, or if I should adapt my python/plot scheme
(5) As Guido said, above: as a replacement for C, or at it's best, where
I probably wouldn't have written a C program at all, but used a
calculator or 'bc' and a pencil. Often, what I think is going to
be a small job ends up getting more complicated.
Example: We got a new detector for our X-ray spectrometer, and since
the absorption characteristics was radically different from the
previous ones, we had to rebuild our least-squares-fit elemental
references from scratch. ( Something I had never done and no one
else remembered doing - I used to go to our Physicist and get some
"magic numbers" to plug in - now all I had was one of his papers. )
Part of the process involved peak ratio's ( weighted by atom ratio's)
of "binary" standards : KCl, NaCl, Na2SO4 - something I could have
done with a calculator, but I had the feeling that it probably wouldn't
work right the first time, so I might as well write a Python program to
do it. Well: I didn't work out the first time. There was obviously
someting wrong with the data going in, and I was glad I wrote a
python program which I could extend to do some detective work:
The program calculated the ratio's, added the inverse ratio's to a
table, and given any one initial absolute value, it calculated the
values of all of the other elements recursively, sorted them by both
value and element and printed them along with a "trace". Inconsistencies
were easier to spot and the trace helped to show which sample was "bad".
( If you started with Ca = 1.0, it generate values from all of the
Ca-to-something ratio's, then all of the something to something else,
etc. so you would end up with, say, 4 values for Mg, derrived from
different chains of ratios, and if the were not all nearly equal,
then some value up the chain was bad. ) The fact that I did not
have to deal with any low level list-pointer processing made none
of this daunting. ( Even though it had become a bigger job than I
initially thought, it STILL had to be done in a couple days! )
Sorry if I bore you with details, but I just wanted to illustrate
how sometimes those "quickies" end up being bigger jobs that you
expected. ( I'm sure everyone has there own experience of that sort. )
And I found Python marvelous at that sort of thing. It was simple
to add the "audit trail" to my calculation after I found out that
was needed. It didn't kill any other code. It would have been even
simpler if I had done it in a more object-oriented style. I wasn't
that adept at Python when I started, so I used lists.
I'm currently working more on the data-acquisition end of things,
but if I ever get back to the data-PROCESSING part, an interactive
graphics & statistical package in python might be a good project.
I haven't tried the socket library in python yet, but since current
jobs involve some distributed processing, I will probably use python
to interactively debug my applications with a prototype ("stub") server.
Much Thanks for a great tool, Guido!
======== "If you have a hammer, find a nail" - George Bush,'91 =========
Steven D. Majewski University of Virginia Physiology Dept.
sdm7g@Virginia.EDU Box 449 Health Sciences Center
Voice: (804)-982-0831/32 1300 Jefferson Park Avenue
FAX: (804)-982-1616 Charlottesville, VA 22908