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


Groups > comp.lang.python > #26246

Re: Linux shell to python

Date 2012-07-30 13:31 +0200
From Jürgen A. Erhard <jae+python@jaerhard.com>
Subject Re: Linux shell to python
References <1343631941.7199.YahooMailNeo@web193104.mail.sg3.yahoo.com> <5016637A.7060008@phihag.de>
Organization Lost Worlds Inc. (I keep dreaming)
Newsgroups comp.lang.python
Message-ID <mailman.2725.1343647968.4697.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

Re: Linux shell to python Jürgen A. Erhard <jae+python@jaerhard.com> - 2012-07-30 13:31 +0200

csiph-web