[BangPypers] win32com.client.Dispatch

Noufal Ibrahim noufal at gmail.com
Tue Dec 27 13:11:19 CET 2011


Nitin Kumar <nitin.nitp at gmail.com> writes:

> Hi All,
>
> Say I did
> x=win32com.client.Dispatch("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")
>
> where the clsid used is for window media palyer.
> Now if i do:
>>>> dir(x)
> ['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_',
> '__AttrToID__', '__LazyMap__', '__call__', '__doc__', '__eq__',
> '__getattr__', '__getitem__', '__init__', '__int__', '__len__',
> '__module__', '__ne__', '__nonzero__', '__repr__', '__setattr__',
> '__setitem__', '__str__', '_builtMethods_', '_enum_',
> '_find_dispatch_type_', '_get_good_object_', '_get_good_single_object_',
> '_lazydata_', '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_',
> '_print_details_', '_proc_', '_unicode_to_string_', '_username_',
> '_wrap_dispatch_']
>
> It won't show any function related to this specific dll. This happens with
> any COMObject.
> So, is there any way to find out what all functions can be used with this
> object. (or any doc to give more depth)

I remember that the __getattr__ of the object is overridden to lookup
available functions and call them when you actually invoke the
functions. It's been a while so I'm not totally sure. It's the same with
ctypes.

In [14]: from ctypes import cdll
In [15]: so = cdll.LoadLibrary("libc.so.6")
In [16]: so.printf
Out[16]: <_FuncPtr object at 0x1f4de20>
In [17]: so.something_nonsenical
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/noufal/github/nibrahim/openlibrary/<ipython console> in <module>()

/usr/lib/python2.6/ctypes/__init__.pyc in __getattr__(self, name)
    364         if name.startswith('__') and name.endswith('__'):
    365             raise AttributeError(name)
--> 366         func = self.__getitem__(name)
    367         setattr(self, name, func)
    368         return func

/usr/lib/python2.6/ctypes/__init__.pyc in __getitem__(self, name_or_ordinal)
    369 
    370     def __getitem__(self, name_or_ordinal):
--> 371         func = self._FuncPtr((name_or_ordinal, self))
    372         if not isinstance(name_or_ordinal, (int, long)):
    373             func.__name__ = name_or_ordinal

AttributeError: /lib/x86_64-linux-gnu/libc.so.6: undefined symbol: something_nonsenical

There's also some kind of caching in place so that the lookup is not
necessary again

In [19]: "scanf" in dir(so)
Out[19]: False

In [20]: so.scanf
Out[20]: <_FuncPtr object at 0x22511f0>

In [21]: "scanf" in dir(so)
Out[21]: True


This is with ctypes and as far as I know, it's similar to the win32com
API.

Thanks


-- 
~noufal
http://nibrahim.net.in

I tripped over a hole that was sticking up out of the ground.


More information about the BangPypers mailing list