Linux shell to python
张少华
zhangshaohua20101010 at gmail.com
Mon Jul 30 07:09:50 EDT 2012
you can use commands.getstatusoutput(command), the shell command special charactor (like "$ and so on )should be escaped!
在 2012年7月30日星期一UTC+8下午3时40分04秒,Chris Angelico写道:
> On Mon, Jul 30, 2012 at 5:05 PM, Vikas Kumar Choudhary
>
> <vikas.choudhary at yahoo.co.in> 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'
>
>
>
> Welcome!
>
>
>
> 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.
>
>
>
> ChrisA
More information about the Python-list
mailing list