Help With PyParsing of output from win32pdhutil.ShowAllProcesses()
David
wizzardx at gmail.com
Tue Sep 11 14:42:43 EDT 2007
On 9/11/07, Steve <sreisscruz at gmail.com> wrote:
> Hi All (especially Paul McGuire!)
>
> Could you lend a hand in the grammar and paring of the output from the
> function win32pdhutil.ShowAllProcesses()?
>
> This is the code that I have so far (it is very clumsy at the
> moment) :
Any particular reason you need to use pyparsing? Seems like an
overkill for such simple data.
Here's an example:
import pprint
X="""Process Name ID Process,% Processor Time,% User Time,%
Privileged Time,Virtual Bytes Peak,Virtual Bytes
PyScripter 2572 0 0 0 96370688 96370688
vmnetdhcp 1184 0 0 0 13942784 13942784
vmount2 780 0 0 0 40497152 38400000
ipoint 260 0 0 0 63074304 58531840"""
data = []
for line in X.split('\n')[1:]: # Skip the first row
split = line.split()
row = [split[0]] # Get the process name
row += [int(x) for x in split[1:]] # Convert strings to int, fail
if any aren't.
data.append(row)
pprint.pprint(data)
# Output follows:
#
#[['PyScripter', 2572, 0, 0, 0, 96370688, 96370688],
# ['vmnetdhcp', 1184, 0, 0, 0, 13942784, 13942784],
# ['vmount2', 780, 0, 0, 0, 40497152, 38400000],
# ['ipoint', 260, 0, 0, 0, 63074304, 58531840]]
#
More information about the Python-list
mailing list