Python wmi c.Win32_PerfFormattedData_PerfOS_Proces

2019-08-18 05:53发布

问题:

>>> for i in c.Win32_PerfFormattedData_PerfOS_Processor():
...    print i
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\work\pythonsv\vendor\wmi.py", line 1029, in __getattr__
    return getattr (self._namespace, attribute)
  File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 496, in
__getattr__
    raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: <unknown>.Win32_PerfFormattedData_PerfOS_Processor

Anyone could explain this traceback? Made a remote call on WIN7 machine.

回答1:

AttributeError means that the object c doesn't have an attribute Win32_PerfFormattedData_PerfOS_Processor.

The "" indicates that Python asked c to describe itself and c returned the string "" (which obviously isn't terribly helpful). It appears you've created c, so it would illuminate the problem more if you would include the code that created c.

My best guess is that c is some sort of WMI wrapper, but that WMI object doesn't have the Win32_PerfFormattedData_PerfOS_Processor function/method/attribute.

The underlying cause is that either you're not using c as designed (maybe you're missing some run-time components) or c isn't initialized properly.



回答2:

UPDATE:

this worked: i.e. at cmd --> lodctr /q

[link] http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/perfmon-problems-unable-to-add-counters/e90f231d-0014-457d-8b1f-5f342971597a