import win32com.client
objSWbemServices = win32com.client.Dispatch(
"WbemScripting.SWbemLocator").ConnectServer(".","root\cimv2")
for item in objSWbemServices.ExecQuery(
"SELECT * FROM Win32_PnPEntity "):
found=False
for name in ('Caption','Capabilities '):
a = getattr(item, name, None)
if a is not None:
b=('%s,' %a)
if "Item" in b:
print "found"
found = True
else:
print "Not found"
break
我只想一次显示“找到”否则“未找到”