Linux shell to python

Chris Angelico rosuav at
Mon Jul 30 09:40:04 CEST 2012

On Mon, Jul 30, 2012 at 5:05 PM, Vikas Kumar Choudhary
<vikas.choudhary at> 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'


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.


More information about the Python-list mailing list