output of top on a linux box

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Apr 9 17:32:59 EDT 2007


En Mon, 09 Apr 2007 14:56:03 -0300, Pradnyesh Sawant <spradml at gmail.com>  
escribió:

> Thanks for the pointer to use /proc/stat
> However, that does not answer my other question about string slicing
> Any pointers in that direction would be helpful...
>
>> > top = os.popen("top -n 1")
>> > rd = top.read().split("\n")
>> > splt = rd[2].split()
>> > # cpu = splt[2][:-4]  # why ain't this working ???
>> > cpu = splt[2]
>> > print "cpu usage: %s, %s" % (cpu, type(cpu))

Print rd[2] above and see how it is formatted.

-- 
Gabriel Genellina




More information about the Python-list mailing list