[python-win32] WMI module - Properties Order
Tim Roberts
timr at probo.com
Thu Jan 5 02:11:11 CET 2012
Tim Roberts wrote:
> pierre baral wrote:
>> In fact, I would like to generate a code that is generic... without
>> knowing the name of the properties (so without calling obj.property) !
>>
>> Check my example:
>>
>> c = wmi.WMI()
>> wql = "Select Name, Caption, Description From Win32_Blabla"
>> objs = c.query(wql)
>>
>> for obj in objs:
>> props = [getattr(obj, p) for p in obj.properties]
>> print "%s" % (";" . join ([p for p in props]))
>>
>> Actually it will print the props list with the obj.properties order
>> (not the order
>> of my request)
>>
>> Any tips to keep the order of my request? So It's not possible? ;'(
> Not possible. You will have to pass the field ordering from the query
> along to the renderer somehow.
c = wmi.WMI()
flds = ('Name','Caption','Description')
wql = 'Select ' + ','.join(flds) + ' From win32_blabla'
objs = (flds,c.query(wql))
...
for obj in objs[1]:
props = [getattr(obj,p) for p in objs[0]]
print ';'.join(props)
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list