<div>You&nbsp;are asking the obvious...&nbsp;or&nbsp;rather&nbsp;it <em>should</em>&nbsp;have been obvious. But unfortunately&nbsp;it wasn&#39;t...</div>
<div>&nbsp;</div>
<div>Yes, </div>
<div>&nbsp;</div>
<div>result=win32com.client.Dispatch(&quot;COMClass&quot;)[&quot;ItemName&quot;] </div>
<div>&nbsp;</div>
<div>works. </div>
<div>&nbsp;</div>
<div>As for your&nbsp;final suggestion&nbsp;(which is excellent). We do have a TLB and I have already fooled around with a tlbimp generated interop dll.&nbsp;However it doesn&#39;t help in respect to making it possible to run our CPython scripts in IronPython. Something that is not simple to accomplish when COM interop rears it&#39;s ugly head.
</div>
<div>&nbsp;</div>
<div>Thank you very much for the quick reply - even though it made me want to bang my head into the table ;-)</div>
<div>&nbsp;</div>
<div>BR</div>
<div>Martin<br><br>&nbsp;</div>
<div><span class="gmail_quote">On 7/11/07, <b class="gmail_sendername">Dino Viehland</b> &lt;<a href="mailto:dinov@exchange.microsoft.com">dinov@exchange.microsoft.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div lang="EN-US" vlink="purple" link="blue">
<div>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">I could be asking the obvious but do square brackets work for you?</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">&nbsp;</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">I would expect:</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">&nbsp;</span></p>
<p>result=win32com.client.Dispatch(&quot;COMClass&quot;)[&quot;ItemName&quot;]</p>
<p>result=win32com.client.Dispatch(&quot;COMClass&quot;)[0]</p>
<p>&nbsp;</p>
<p>to work or possibly:</p>
<p>&nbsp;</p>
<p>result=win32com.client.Dispatch(&quot;COMClass&quot;).Item[0]</p>
<p>&nbsp;</p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">Another possibility is selecting the overloads on get_Item.&nbsp; I don't know why we'd think there'd be two object versions but bound methods will have an "Overloads" property (after importing clr or another .NET namespace) which might help you (I'm not sure it will, but it's worth a shot).
</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">&nbsp;</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">Finally I would suggest that you could also look into making a PIA (Primary Interop Assembly) for your COM objects if you have a TLB instead of writing your own dispatch code.&nbsp; A tool ships w/ the .NET framework called tlbimp so if you have a TLB for your COM objects you can use that to generate an assembly.&nbsp; Add a reference to that assembly and you might find that you have a better COM experience.&nbsp; Unfortunately that only helps if you have a TLB available.
</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">&nbsp;</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">Hopefully one of those will help.</span></p>
<p><span style="FONT-SIZE: 11pt; COLOR: #1f497d">&nbsp;</span></p>
<div style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
<p><b><span style="FONT-SIZE: 10pt">From:</span></b><span style="FONT-SIZE: 10pt"> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com
</a> [mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Martin<br><b>Sent:</b> Wednesday, July 11, 2007 7:45 AM
<br><b>To:</b> <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users@lists.ironpython.com" target="_blank">users@lists.ironpython.com</a><br><b>Subject:</b> [IronPython] &quot;TypeError: Microsoft.Scripting.DynamicType
 is not callable&quot; bug(?)</span></p></div>
<div><span class="e" id="q_113b61264fe80ead_1">
<p>&nbsp;</p>
<div>
<p>Hi,</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p><strong>Background:</strong></p></div>
<div>
<p>We have a number of Python scripts that we use for updating and setting up the devices my company make. We do this&nbsp;through calls to a number of COM classes&nbsp;via win32com.client.Dispatch().</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>We are interested in being able to call these Python scripts from various .NET GUI applications written in C# so naturally I started looking into IronPython.</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>My goal is to make&nbsp;our CPython code as&nbsp;executable in IronPython as humanly possible so since win32com is not available through IronPython I wrote a simple C# interop wrapper handling the interops for&nbsp;the specific&nbsp;COM classes we need to call when setting up our devices: 
</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>namespace win32com<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public class client<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</p></div>
<div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static object Dispatch(string comName)</p></div>
<div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p></div>
<div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;rip&gt;</p></div>
<div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p></div>
<div>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>}</p></div>
<div>
<p><br>The annoying thing is that&nbsp;this &quot;hack&quot;&nbsp;works like a charm except in one type of case.</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p><strong>Problem:</strong></p></div>
<div>
<p>Some of our COM classes return Item collections that are indexable by both specific names (string indexing)&nbsp;and normal int indexes</p></div>
<div>
<p>-&nbsp;example in CPython: result=win32com.client.Dispatch(&quot;COMClass&quot;)(&quot;ItemName&quot;)&nbsp;and/or result=win32com.client.Dispatch(&quot;COMClass&quot;)(0)</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>This works like a charm in CPython (and the interop version of our C# code for that matter) but it does&nbsp;NOT work in IronPython.</p></div>
<div>
<p>In IronPython 1.1 I get this error message &quot;TypeError: object is not callable&quot;</p></div>
<div>
<p>In IronPython 2.0 alpha 3 I get this error message: &quot;TypeError: Microsoft.Scripting.DynamicType is not callable&quot;.</p></div>
<div>
<div>
<p>&nbsp;</p></div>
<div>
<p>I can access the properties of the object such as item count however I cannot index into the result object by calling result.get_Item(&quot;ItemName&quot;). It gives the following error message</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>TypeError: multiple overloads of get_Item could match (String)<br>&nbsp; get_Item(Object)<br>&nbsp; get_Item(Object)</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>nor can I index into the result object by calling result.get_Item(0) which gives a similar error except the problematic match is Int32.</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>So&nbsp;apparently&nbsp;IronPython cannot identify the type of the index objects when more are present?</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p><strong>Question</strong></p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>Anyone have any comments that can help me here? Have I missed some subtle issues with COM interop? Is this a known bug and if so when do you think it will be fixed?</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>(I know I can get around the problem by writing&nbsp;specific IronPython code + changing the handling of the COM class in my C# wrapper but I REALLY don&#39;t want to nor should I have to if the goal is to make IronPython as clean as possible port of CPython.) 
</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>PS.</p></div>
<div>
<p>Great initiative and great work otherwise in the port</p></div>
<div>
<p>&nbsp;</p></div>
<div>
<p>BR</p></div>
<div>
<p>Martin Storm Møller</p></div></div>
<div>
<p>&nbsp;</p></div></span></div></div></div><br>_______________________________________________<br>users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:users@lists.ironpython.com">users@lists.ironpython.com
</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br><br>
</blockquote></div><br>