Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; '(using': 0.07; 'bash': 0.07; 'python': 0.09; 'grep': 0.09; 'porting': 0.09; 'subject:python': 0.11; 'do,': 0.15; 'cleaner': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subprocess': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'implementing': 0.17; 'shell': 0.18; 'trying': 0.21; 'received:209.85.214.174': 0.21; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'message- id:@mail.gmail.com': 0.27; 'initial': 0.28; 'invoke': 0.29; 'kumar': 0.29; 'probably': 0.29; 'usually': 0.30; 'code': 0.31; 'implement': 0.32; 'achieving': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'possible': 0.37; 'level': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'end': 0.40; "you'll": 0.62; 'back': 0.62; '30,': 0.62; 'more': 0.63; 'jul': 0.65; 'cut': 0.71; 'directly.': 0.78; 'technically': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0VlyCLto+l6yXIUfGeHh3t+Kfhv3ThVSUUsXE5EZHQw=; b=TgughBr0yzXUZu1O1BGH9zkMW1uLTcknYOIp2OBbyjdi+VuW4lu3c121CzfV43IYfK Ggqt7wPiUYjfOdK9TWRCkask6065fq7mZ0KOW10lEwmJ2iagEnwzHHwag4eiDDVOjwmJ gE+JT9K8tvkE1roftkA1xC0f70/MYfSg4R96mF6y26NYhF4HkzJBM4dRzXNJhKjA4tg/ N1Er4oDA9aLCT9Be5yXsDwKv+dmkXFjJmImWhruP5CGC6gJ4SZYCGUul8pCe1aoYdkgk NKZZUbXVZO5+otlTxf4OY5xV/riSMVkggn4hh2sreEJRS3exb1oKt9IVKHERClNPrQqv L/Ew== MIME-Version: 1.0 In-Reply-To: <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com> References: <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com> Date: Mon, 30 Jul 2012 17:40:04 +1000 Subject: Re: Linux shell to python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343634007 news.xs4all.nl 6952 [2001:888:2000:d::a6]:39010 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26233 On Mon, Jul 30, 2012 at 5:05 PM, Vikas Kumar Choudhary wrote: > > I was trying porting from bash shell to python. > > let me know if someone has tried to implement (grep and PIPE) shell commands in python `lspci | grep Q | grep "$isp_str1" | grep "$isp_str2" | cut -c1-7' Welcome! While it's technically possible to do exactly that in Python (using subprocess as you describe), there's usually a more efficient and cleaner method of achieving the same goal. With a port such as you describe, it's probably best to go right back to the conceptual level and work out what exactly you're trying to do, and then look at implementing that in Python. You'll end up with much cleaner code at the end of it. For an initial guess, I would say that you'll use subprocess to invoke lspci, but then everything else will be done in Python directly. ChrisA