Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26242

Re: Linux shell to python

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <phihag@phihag.de>
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; 'strings.': 0.07; 'verbatim': 0.07; 'python': 0.09; 'grep': 0.09; 'parameter.': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; "'q'": 0.16; 'filename:fname piece:signature': 0.16; 'rough': 0.16; 'subprocess': 0.16; 'wrote:': 0.17; 'equivalent': 0.20; 'import': 0.21; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'kumar': 0.29; 'recommended': 0.33; 'received:192.168.2': 0.34; 'correctly': 0.37; 'subject:: ': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'cut': 0.71; 'pipeline': 0.84; 'to:addr:yahoo.co.in': 0.91
Date Mon, 30 Jul 2012 12:35:38 +0200
From Philipp Hagemeister <phihag@phihag.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5
MIME-Version 1.0
To Vikas Kumar Choudhary <vikas.choudhary@yahoo.co.in>
Subject Re: Linux shell to python
References <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com>
In-Reply-To <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com>
X-Enigmail-Version 1.4
OpenPGP id=FAFB085C
Content-Type multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigAF63AA5367E1A0A6E47C04EE"
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2723.1343644555.4697.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343644555 news.xs4all.nl 6952 [2001:888:2000:d::a6]:52959
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26242

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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
]

You can also just paste the whole pipeline with the shell=True
parameter. That's not recommended though, and it's hard to correctly
quote strings.

- Philipp

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Linux shell to python Philipp Hagemeister <phihag@phihag.de> - 2012-07-30 12:35 +0200

csiph-web