Re: Grep Equivalent for Python

2007-03-19 Thread tereglow
On Mar 18, 7:33 pm, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > > > > > > tereglow <[EMAIL PROTECTED]> wrote: > >On Mar 15, 1:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > >> tereglow <[EMAIL PROTECTED]> wrote: > > >>>grep^MemTotal /proc/meminfo | awk '{print $2}' > > >>

Re: Grep Equivalent for Python

2007-03-18 Thread Aahz
In article <[EMAIL PROTECTED]>, tereglow <[EMAIL PROTECTED]> wrote: >On Mar 15, 1:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: >> tereglow <[EMAIL PROTECTED]> wrote: >>> >>>grep^MemTotal /proc/meminfo | awk '{print $2}' >> >> If you would indeed do that, maybe it's also worth learning something

Re: Grep Equivalent for Python

2007-03-18 Thread tereglow
On Mar 15, 1:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > tereglow <[EMAIL PROTECTED]> wrote: > >... > > > server using the /proc FS. For example, in order to obtain the amount > > of physical memory on the server, I would do the following in shell: > > >grep^MemTotal /proc/meminfo | awk

Re: Grep Equivalent for Python

2007-03-14 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > tereglow <[EMAIL PROTECTED]> wrote: >... > > server using the /proc FS. For example, in order to obtain the amount > > of physical memory on the server, I would do the following in shell: > > > > grep ^MemTotal /proc/meminfo | awk '{print $2}' > > If you would indeed do

Re: Grep Equivalent for Python

2007-03-14 Thread Alex Martelli
tereglow <[EMAIL PROTECTED]> wrote: ... > server using the /proc FS. For example, in order to obtain the amount > of physical memory on the server, I would do the following in shell: > > grep ^MemTotal /proc/meminfo | awk '{print $2}' If you would indeed do that, maybe it's also worth learnin

Re: Grep Equivalent for Python

2007-03-14 Thread [EMAIL PROTECTED]
On Mar 14, 10:57 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, Laurent Pointal wrote: > > > Steve Holden a écrit : > >> Regular expressions aren't really needed here. Untested code follows: > > >> for line in open('/proc/meminfo').readlines: > > for line in open(

Re: Grep Equivalent for Python

2007-03-14 Thread Fabio FZero
On Mar 14, 9:37 am, "tereglow" <[EMAIL PROTECTED]> wrote: > Hello all, > > I come from a shell/perl background and have just to learn python. To > start with, I'm trying to obtain system information from a Linux > server using the /proc FS. For example, in order to obtain the amount > of physical

Re: Grep Equivalent for Python

2007-03-14 Thread Steve Holden
tereglow wrote: > Okay, > > It is now working as follows: > > memFile = open('/proc/meminfo') > for line in memFile.readlines(): > if line.startswith("MemTotal"): > memStr = line.split() > memTotal = memStr[1] > memFile.close() > print "Memory: " + memTotal + "kB

Re: Grep Equivalent for Python

2007-03-14 Thread tereglow
Okay, It is now working as follows: memFile = open('/proc/meminfo') for line in memFile.readlines(): if line.startswith("MemTotal"): memStr = line.split() memTotal = memStr[1] memFile.close() print "Memory: " + memTotal + "kB" I'm learning the whole try, f

Re: Grep Equivalent for Python

2007-03-14 Thread tereglow
On Mar 14, 11:57 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > In <[EMAIL PROTECTED]>, Laurent Pointal wrote: > > > Steve Holden a écrit : > >> Regular expressions aren't really needed here. Untested code follows: > > >> for line in open('/proc/meminfo').readlines: > > for line in open(

Re: Grep Equivalent for Python

2007-03-14 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Laurent Pointal wrote: > Steve Holden a écrit : >> Regular expressions aren't really needed here. Untested code follows: >> >> for line in open('/proc/meminfo').readlines: > for line in open('/proc/meminfo').readlines(): for line in open('/proc/meminfo'): >> if line.s

Re: Grep Equivalent for Python

2007-03-14 Thread BJörn Lindqvist
> I come from a shell/perl background and have just to learn python. To > start with, I'm trying to obtain system information from a Linux > server using the /proc FS. For example, in order to obtain the amount > of physical memory on the server, I would do the following in shell: > > grep ^MemTo

Re: Grep Equivalent for Python

2007-03-14 Thread Laurent Pointal
Steve Holden a écrit : > Regular expressions aren't really needed here. Untested code follows: > > for line in open('/proc/meminfo').readlines: for line in open('/proc/meminfo').readlines(): > if line.startswith("Memtotal:"): > name, amt, unit = line.split() > print name, amt,

Re: Grep Equivalent for Python

2007-03-14 Thread Paul Boddie
On 14 Mar, 13:37, "tereglow" <[EMAIL PROTECTED]> wrote: > Hello all, > > I come from a shell/perl background and have just to learn python. Welcome aboard! > To start with, I'm trying to obtain system information from a Linux > server using the /proc FS. For example, in order to obtain the amou

Re: Grep Equivalent for Python

2007-03-14 Thread Steve Holden
tereglow wrote: > Hello all, > > I come from a shell/perl background and have just to learn python. To > start with, I'm trying to obtain system information from a Linux > server using the /proc FS. For example, in order to obtain the amount > of physical memory on the server, I would do the fol

Grep Equivalent for Python

2007-03-14 Thread tereglow
Hello all, I come from a shell/perl background and have just to learn python. To start with, I'm trying to obtain system information from a Linux server using the /proc FS. For example, in order to obtain the amount of physical memory on the server, I would do the following in shell: grep ^MemT