Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.04; '(especially': 0.07; 'method,': 0.07; 'python': 0.08; 'inclined': 0.09; 'myself,': 0.09; 'scripts,': 0.09; 'underlying': 0.09; 'pm,': 0.10; 'scripts': 0.10; 'wrote:': 0.14; 'angelico': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:scripts': 0.16; "system's": 0.16; 'try/except': 0.16; 'input': 0.17; 'mon,': 0.17; 'shell': 0.19; 'header:In-Reply- To:1': 0.21; 'primarily': 0.22; 'trying': 0.23; 'elegant': 0.23; 'received:209.85.210.174': 0.23; 'received:mail- iy0-f174.google.com': 0.23; 'code': 0.24; 'subject: -- ': 0.25; "i'm": 0.27; 'work.': 0.28; 'message-id:@mail.gmail.com': 0.28; 'thanks': 0.28; 'keeps': 0.28; 'language.': 0.28; 'subject:?': 0.29; 'import': 0.29; 'toward': 0.29; 'code,': 0.29; 'second': 0.30; 'module': 0.30; 'usually': 0.32; 'done,': 0.32; 'value.': 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'greatly': 0.33; 'things': 0.33; 'rather': 0.34; 'chris': 0.34; 'however,': 0.34; 'there': 0.35; 'else': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; '20,': 0.37; 'stephen': 0.37; 'ways': 0.37; 'another': 0.37; 'communicate': 0.37; 'two': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'appreciated': 0.38; 'subject:: ': 0.38; "i'd": 0.39; 'received:209': 0.39; 'flexibility': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'kind': 0.60; 'your': 0.60; 'back': 0.63; 'cause': 0.67; 'processes,': 0.67; 'legal': 0.70; 'hand,': 0.74; 'worthy': 0.84; 'protection,': 0.91; 'safe.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=t93y46bgPy6tAE9UYM2GGtbtGhx4w41mQ6TFCHkUOUE=; b=rdQkngREfnRAoqq0OVozDzU2ZY7n6M6QeXI6QWiVnnP8C1uxPS8WLCZvRW40befi/o QeIx87dwJfFXlUVlBPWPExTzehwLfb52hntGi9YnNPTEMQ5qQgc08JvioCXS5ifdBGrR dq8yC31I+Y85v5cRZKcJ7cxZ/YJEhyK+Pa4AE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=F0gvzb6J5bpu+gqFAL3zhzcmvvrn3uGolvLrWhFpB/mk+Yvt68iGD1pwAu92oV4e7M oIU8FxRFmbVDewMsSEWamSTQCqCc44WQb6QR6yu4XwJfuwR8yJ1APPWjpNpJBbk5c7Yu Co71geKeUin22tZhC3f9uIjxwQFLI3cGwpR8k= MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 20 Jun 2011 14:26:58 +1000 Subject: Re: running multiple scripts -- which way is more elegant? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308544021 news.xs4all.nl 49174 [::ffff:82.94.164.166]:36758 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7997 On Mon, Jun 20, 2011 at 2:13 PM, Stephen Bunn wrote: > List, > > =A0 First I'm very new to Python. I usually do this kind of thing with sh= ell > scripts, however, I'm trying to move to using python primarily so I can > learn the language. A worthy cause :) > ...=A0 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.= =A0 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