Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.python

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2012, 11:31 AM
Jürgen A. Erhard
Guest
 
Posts: n/a
Default Re: Linux shell to python

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"

Grits, J
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 03:37 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.