Hi Tim:<br><br>So what you are saying is that it would be perfectly acceptable to have a &quot;for loop&quot; for each Win32_* query and that&nbsp; there is no good way to generalise that behaviour. <br><br>eg. <br><br>class Process()<br>
&nbsp;&nbsp; ...<br>class Product()<br>

&nbsp; ...<br>

class Event()<br>
&nbsp; ...<br>
class Service()<br>
&nbsp;&nbsp; ....  <br>
<br>
if __name__ == &#39;__main__&#39;:<br>
 &nbsp; setup_all (True)<br>
 &nbsp; c = wmi.WMI ()<br>
 &nbsp; for process in c.Win32_Process ([&#39;ProcessId&#39;, &#39;Caption&#39;]):<br>
 &nbsp; &nbsp; d = dict ((p, getattr (process, p)) for p in process.properties)<br>
 &nbsp; &nbsp; Process (**d)<br>
<br>
 &nbsp; for product in c.Win32_Products ([&#39;ProductId&#39;, &#39;Caption&#39;]):<br>

 &nbsp; &nbsp; d = dict ((p, getattr (process, p)) for p in product.properties)<br>

 &nbsp; &nbsp; Product (**d)<br>

<br>
 &nbsp; for event in c.Win32_NTEvent ([&#39;EventId&#39;, &#39;Caption&#39;]):<br>

 &nbsp; &nbsp; d = dict ((p, getattr (event, p)) for p in event.properties)<br>

 &nbsp; &nbsp; Event (**d)<br>

<br>
 &nbsp; for service in c.Win32_Service ([&#39;ServiceId&#39;, &#39;Caption&#39;]):<br>

 &nbsp; &nbsp; d = dict ((p, getattr (service, p)) for p in service.properties)<br>

 &nbsp; &nbsp; Service (**d)<br>

<br><br>&nbsp; ....<br>&nbsp; etc etc.<br>
 &nbsp; session.flush ()<br>
 &nbsp; session.close ()<br><br>Thanks for your patience.<br>
<br>
Cheers<br>
Mark<br>
<br><div><span class="gmail_quote">On 11/03/2008, <b class="gmail_sendername">Tim Golden</b> &lt;<a href="mailto:mail@timgolden.me.uk">mail@timgolden.me.uk</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
mark.a.brand wrote:<br> &gt; sorry - client as in customer<br> <br> <br>Ah. I see. (Didn&#39;t think of that :)<br> <br><br> &gt; i will try and explain better, but its not quite clear in my mind what is<br> &gt; achievable ...<br>
 &gt;<br> &gt; so to build up these database tables, i have to have some queries happening<br> &gt; of the form :<br> &gt;<br> &gt; for list in Win32_Process()<br> &gt;&nbsp;&nbsp;add instance to table-process<br> &gt;<br> &gt; for list in Win32_Service()<br>
 &gt;&nbsp;&nbsp;add instance to table-service<br> &gt;<br> &gt; ...<br> &gt; etc etc for each Win32_* query i wanted to implement.<br> &gt;<br> &gt; what I am looking for is an object based / pythonic way to replace all those<br> &gt; &quot;for loops&quot;.<br>
 <br> <br>Certainly possible at several levels. There are a number<br> of ORM packages around, but the general favourite is probably<br> sqlalchemy [1] and its spin-off Elixir [2]. That said, there&#39;s<br> nothing to stop you working straight at the DBAPI [3] level<br>
 and calling .executemany against the tables you want.<br> <br> Certainly you could have your table structure exactly mimic<br> the &quot;column&quot; structure of the corresponding WMI class and<br> push things along a bit that way. It&#39;s fairly trivial to<br>
 turn the WMI attribute values into a dictionary which could<br> then be passed on to something like Elixir&#39;s row-creation.<br> <br> &lt;vague hand-wavy code&gt;<br> import os, sys<br> from elixir import *<br> import wmi<br>
 <br> DB_FILENAME = os.path.abspath (&quot;wmi.db&quot;)<br> metadata.bind = &quot;sqlite:///%s&quot; % DB_FILENAME<br> <br> class Process (Entity):<br> <br>&nbsp;&nbsp; ProcessId = Field (Integer, primary_key=True)<br>&nbsp;&nbsp; Caption = Field (Unicode (100))<br>
 <br> if __name__ == &#39;__main__&#39;:<br>&nbsp;&nbsp; setup_all (True)<br>&nbsp;&nbsp; c = wmi.WMI ()<br>&nbsp;&nbsp; for process in c.Win32_Process ([&#39;ProcessId&#39;, &#39;Caption&#39;]):<br>&nbsp;&nbsp;&nbsp;&nbsp; d = dict ((p, getattr (process, p)) for p in process.properties)<br>
&nbsp;&nbsp;&nbsp;&nbsp; Process (**d)<br> <br>&nbsp;&nbsp; session.flush ()<br>&nbsp;&nbsp; session.close ()<br> <br> &lt;/code&gt;<br> <br> Obviously, this is a mere stub but it does at least work<br> and might be a useful basis. There is definite scope for<br>
 factoring things out but you might do better just to have<br> a function which took -- or inferred -- the relevant class<br> and table names. YMMV.<br> <br><br> &gt; thanks for you assistance tim.<br> <br> <br>Glad to be of service<br>
 <br> :)<br> <br> TJG<br> <br> [1] <a href="http://sqlalchemy.org">http://sqlalchemy.org</a><br> [2] <a href="http://elixir.ematia.de/trac/wiki">http://elixir.ematia.de/trac/wiki</a><br> [3] <a href="http://www.python.org/dev/peps/pep-0249/">http://www.python.org/dev/peps/pep-0249/</a><br>
 <br><br> _______________________________________________<br> python-win32 mailing list<br> <a href="mailto:python-win32@python.org">python-win32@python.org</a><br> <a href="http://mail.python.org/mailman/listinfo/python-win32">http://mail.python.org/mailman/listinfo/python-win32</a><br>
 </blockquote></div><br>