[python-win32] Strange/impossible Python COM interface behavior

Emlyn Jones emlynj at gmail.com
Wed Jul 4 18:21:52 CEST 2007


On 7/4/07, Richard Bell <rbell01824 at earthlink.net> wrote:
>
> In my continued work on a COM automation interface for IE I've encountered a
> strange/impossible Python behavior.  Here's what appears to be the offending
> code:
>
> ----- code -----
>         nodes = self.DomGetNListFilterValue(node, tags, properties, value,
>                                             intoFrames, errorFlag, message)
>         print 'DomGetANodeFilterValue', nodes
>         #DomGetANodeFilterValue [<win32com.gen_py.Microsoft HTML Object
> Library.DispHTMLInputElement instance at 0x34839088>]
>         print 'DomGetANodeFilterValue', len(nodes)
>         #DomGetANodeFilterValue 1
>         print 'DomGetANodeFilterValue[%s]'%nodes[0]
>         #DomGetANodeFilterValue[]
>         if len(nodes) == 1:
>             print 'DomGetANodeFilterValue[%s]'%(nodes[0])
>             #DomGetANodeFilterValue[]
>             #but under debugger,
>             #nodes[0]
>             #<win32com.gen_py.Microsoft HTML Object
> Library.DispHTMLInputElement instance at 0x34839088>
>             return nodes[0]
> ----- end code -----
>
> The call to DomGetNListFilterValue returns a list with 1 object per the
> print statements (the comments contain the print statements output).  But an
> attempt to reference the object returns nothing per the following print
> statement.  Curiously, setting a break point and referencing nodes[0] DOES
> return the correct value!?!  I've never seen this kind of behavior.  Does
> anyone have any clues?
>
Hello,
Not had much to do with COM but I would check out what
<win32com.gen_py.Microsoft HTML Object> Library.DispHTMLInputElement'
s implementation of __str__ does. What happens if you try
nodes[0].__repr__() (or nodes[0].__unicode__()?)
I can't think off the top of my head what the builtin to retrieve a
list item is from a list object but that might be worth checking too.

Cheers,
Emlyn.
-- 
()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments


More information about the Python-win32 mailing list