[python-win32] Getting Network Information/Statistics
Tim Roberts
timr at probo.com
Thu Jan 24 20:29:07 CET 2008
Alexander Belyaev wrote:
> I am new to python and so far could not figure out what 'tp' means in
> the following?
>
> Thanks,
> Alexander
>
> tp,val = win32pdh.GetFormattedCounterValue( hc,
> win32pdh.PDH_FMT_LONG )
> print hex(tp),val
>
The PdhGetFormattedCounterValue API has two output parameters: the type
of data returned, and the value of the counter.
win32pdh.GetFormattedCounterValue handles that by returning a tuple of
the 2 values. I could have written it this way:
ret = win32pdh.GetFormattedCounterValue( hc, win32pdh.PDH_FMT_LONG )
print hex(ret[0]), ret[1]
but the Python assignment statement allows me to assign the values of a
tuple to individual variables. So, for example, I can say either:
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> xxx = (1,2,3)
>>> xxx
(1, 2, 3)
>>> a, b, c = (1,2,3)
>>> a
1
>>> b
2
>>> c
3
>>>
In the code you quoted, "tp" receives the counter's type, and "val" gets
the value. "type" is a built-in function in Python, so it's not safe to
us it as a variable name.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list