Grep Equivalent for Python
tereglow
tom.rectenwald at eglow.net
Wed Mar 14 12:37:36 EDT 2007
On Mar 14, 11:57 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> In <et8u0e$k2... at news2.u-psud.fr>, 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.startswith("Memtotal:"):
> >> name, amt, unit = line.split()
> >> print name, amt, unit
> >> break
>
> Of course it's cleaner to assign the file object to a name and close the
> file explicitly after the loop.
>
> Ciao,
> Marc 'BlackJack' Rintsch
Thanks all for the help with this, am learning a lot; really
appreciate it.
Tom
More information about the Python-list
mailing list