Re: Linux shell to python

2012-07-31 Thread Barry Scott
On 30 Jul 2012, at 23:56, Dan Stromberg wrote: > > On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott wrote: > lspci gets all its information from the files in /sys/bus/pci/devices. > > You can use os.listdir() to list all the files in the folder and then open > the files you want to get the data

Re: Linux shell to python

2012-07-31 Thread 88888 Dihedral
Mark Lawrence於 2012年7月31日星期二UTC+8下午3時15分32秒寫道: > On 31/07/2012 02:20, Dennis Lee Bieber wrote: > > > On Mon, 30 Jul 2012 22:56:48 +, Dan Stromberg > > > declaimed the following in gmane.comp.python.general: > > > > > > > > >> Sigh, and I'm also not keen on multi-line list comprehensions,

Re: Linux shell to python

2012-07-31 Thread Alister
On Tue, 31 Jul 2012 08:15:32 +0100, Mark Lawrence wrote: > On 31/07/2012 02:20, Dennis Lee Bieber wrote: >> On Mon, 30 Jul 2012 22:56:48 +, Dan Stromberg >> declaimed the following in gmane.comp.python.general: >> >> >>> Sigh, and I'm also not keen on multi-line list comprehensions, >>> speci

Re: Linux shell to python

2012-07-31 Thread Chris Angelico
On Tue, Jul 31, 2012 at 5:15 PM, Mark Lawrence wrote: > On 31/07/2012 02:20, Dennis Lee Bieber wrote: >> >> should be pecked to death by a dead parrot. >> > > Any particular species? I'm sure that, if you're in Norway, you could find an appropriate bird. But for those of us for whom that's not an

Re: Linux shell to python

2012-07-31 Thread Mark Lawrence
On 31/07/2012 02:20, Dennis Lee Bieber wrote: On Mon, 30 Jul 2012 22:56:48 +, Dan Stromberg declaimed the following in gmane.comp.python.general: Sigh, and I'm also not keen on multi-line list comprehensions, specifically because I think they tend to make less readable code. It also beco

Re: Linux shell to python

2012-07-30 Thread Dan Stromberg
On Mon, Jul 30, 2012 at 11:14 PM, Emile van Sebille wrote: > On 7/30/2012 3:56 PM Dan Stromberg said... > > >> On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott > > > And of course you can write list comprehensions on as many lines as >> it take to make the code maintainable. >> >> Sigh, and

Re: Linux shell to python

2012-07-30 Thread Emile van Sebille
On 7/30/2012 3:56 PM Dan Stromberg said... On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott And of course you can write list comprehensions on as many lines as it take to make the code maintainable. Sigh, and I'm also not keen on multi-line list comprehensions, specifically because I thi

Re: Linux shell to python

2012-07-30 Thread Dan Stromberg
On Mon, Jul 30, 2012 at 9:26 PM, Barry Scott wrote: > lspci gets all its information from the files in /sys/bus/pci/devices. > > You can use os.listdir() to list all the files in the folder and then open > the files you want to get the data you need. > Gee, wouldn't it be more portable to parse

Re: Linux shell to python

2012-07-30 Thread Barry Scott
then): http://pypi.python.org/pypi/sarge/ > Don't know about it's stability/ubs/etc, never used it. > > -Original message- > From: Vikas Kumar Choudhary > Sent: Mon 30-07-2012 09:34 > Subject: Linux shell to python > To: python-list@python.org; > D

RE: Linux shell to python

2012-07-30 Thread Paul van der Linden
You can do this with one subprocess.Popen and some python commands. The alternative is to pipe some subprocess.Popen commands together. Or for the quick way out (but I think you better stick with bash scripting then): http://pypi.python.org/pypi/sarge/ Don't know about it's stability/ubs/etc, n

Re: Linux shell to python

2012-07-30 Thread Philipp Hagemeister
On 07/30/2012 01:31 PM, Jürgen A. Erhard wrote: > On Mon, Jul 30, 2012 at 12:35:38PM +0200, Philipp Hagemeister wrote: >> 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 is

Re: Linux shell to python

2012-07-30 Thread Peter Otten
Vikas Kumar Choudhary wrote: > 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' > > I tried to use python subprocess and OS.Popen modules. subprocess is the way to go. > I was trying

Re: Linux shell to python

2012-07-30 Thread Jürgen A . Erhard
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

Re: Linux shell to python

2012-07-30 Thread 张少华
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 > > wrote: > > > > > > I was trying porting from bash shell to

Re: Linux shell to python

2012-07-30 Thread Philipp Hagemeister
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']).sp

Re: Linux shell to python

2012-07-30 Thread Chris Angelico
On Mon, Jul 30, 2012 at 5:05 PM, Vikas Kumar Choudhary 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

Linux shell to python

2012-07-30 Thread Vikas Kumar Choudhary
Dear friends, I just joined the group. 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'   I tried to use python subprocess and OS.Popen modul