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


Groups > comp.lang.python > #26242 > unrolled thread

Re: Linux shell to python

Started byPhilipp Hagemeister <phihag@phihag.de>
First post2012-07-30 12:35 +0200
Last post2012-07-30 12:35 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#26242 — Re: Linux shell to python

FromPhilipp Hagemeister <phihag@phihag.de>
Date2012-07-30 12:35 +0200
SubjectRe: Linux shell to python
Message-ID<mailman.2723.1343644555.4697.python-list@python.org>

[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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web