Linux shell to python
Philipp Hagemeister
phihag at phihag.de
Mon Jul 30 06:35:38 EDT 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20120730/e43c8c5b/attachment.sig>
More information about the Python-list
mailing list