ISO exemplary Python scripts
timr at probo.com
Mon May 11 06:34:26 CEST 2009
kj <socyl at 987jk.com.invalid> wrote:
>Thanks, but the last bit of your post ("...most of which have the
>ability to run by themselves") makes me wonder whether we mean the
>same thing when we talk of "scripts." Can you give me an example
>of a script that *does not* have the ability to run by itself?
>When I use the word "script" I mean, *by definition*, a piece of
>code that has the ability to run by itself.
>I know that in the python world the distinction between a script
>and a (library) module is not so clear-cut,
Exactly. This is true for many of the languages that are traditionally
interpreted. Things start off as standalone applications and morph into
general purpose modules, or vice versa. As a result, I lazily call any
Python source file a "script".
>But this is not *really* a script as I understand it, because,
>even though it "runs" directly from the command-line, it lacks the
>typical CLI amenities, such as command-line flags, help messages,
>diagnostic messages that are aimed to the "naive user" (i.e. as
>opposed to the developer), etc. The coding of these "CLI amenities"
>is one of aspects of these "exemplary Python scripts" I'm most
>interested in learning about.
In my vocabulary, I'd probably call this an "application".
I guess my basic point is that the standard library contains good examples
of Python programming, and the "Python way of thinking". Command-line
argument processing is not a particularly unique task, so the same
techniques that work for parsing things from files, or for handling
arguments in a list, work equally well for handling arguments, especially
with the help of getopt and optparse.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list