Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'verbatim': 0.07; 'python': 0.09; 'grep': 0.09; 'subject:python': 0.11; "'q'": 0.16; 'received:10.1.0': 0.16; 'rough': 0.16; 'subprocess': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'equivalent': 0.20; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'kumar': 0.29; 'code': 0.31; '+0200,': 0.33; 'qualify': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'but': 0.36; 'charset:us-ascii': 0.36; 'bad': 0.37; 'subject:: ': 0.38; 'received:10': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'content-disposition:inline': 0.60; '30,': 0.62; 'more': 0.63; 'jul': 0.65; 'cut': 0.71; 'received:89': 0.86 Date: Mon, 30 Jul 2012 13:31:30 +0200 From: =?iso-8859-1?B?SvxyZ2VuIEEu?= Erhard To: python-list@python.org Subject: Re: Linux shell to python References: <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com> <5016637A.7060008@phihag.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5016637A.7060008@phihag.de> Organization: Lost Worlds Inc. (I keep dreaming) User-Agent: Mutt/1.5.21 (2010-09-15) 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343647968 news.xs4all.nl 6919 [2001:888:2000:d::a6]:41594 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26246 On Mon, Jul 30, 2012 at 12:35:38PM +0200, Philipp Hagemeister wrote: > On 07/30/2012 09:05 AM, Vikas Kumar Choudhary wrote: > > `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" | cut -c1-7' > > The rough Python equivalent would be > > import subprocess > [ l.partition(' ')[0] # or l[:7], if you want to copy it verbatim > for l in subprocess.check_output(['lspci']).splitlines() > if 'Q' in l and isp_str1 in l and isp_str2 in l > ] Ouch. A list comprehension spanning more than one line is bad code pretty much every time. But you did qualify it as "rough" :D Grits, J