running multiple scripts -- which way is more elegant?

Chris Angelico rosuav at gmail.com
Mon Jun 20 00:26:58 EDT 2011


On Mon, Jun 20, 2011 at 2:13 PM, Stephen Bunn <scbunn at sbunn.org> wrote:
> List,
>
>   First I'm very new to Python. I usually do this kind of thing with shell
> scripts, however, I'm trying to move to using python primarily so I can
> learn the language.

A worthy cause :)

> ...  I have come up with two ways to
> accomplish what I'm trying to do and I'm looking for the more elegant
> solution -- or if there is another solution that I have not thought of.  Any
> input would be greatly appreciated and thanks for your time.

Your first method is language-independent. The underlying scripts
merely need to be legal shell scripts and they will work. This is a
measure of flexibility that may be of value.

Your second method, on the other hand, avoids reinvoking Python and
myriad processes, which may work out to be rather faster. Also, you
could have the scripts communicate back to the main module more
easily.

I'd be inclined toward the second solution if I'm writing all the code
myself, but very definitely the first if someone else might write one
of the subscripts (especially so if this is going to be distributed
widely) - spawning a new process means that the system's isolation of
processes keeps your system safe. If you don't need that measure of
protection, I would still surround the import and check() call with
try/except and gracefully handle any errors.

There's many ways these things can be done, but I think you've already
hit on the two broad types (import the code, or use stdout/rc).

Chris Angelico



More information about the Python-list mailing list