Suraj Barkale schrieb: > Is there a way to do the following? > > try: > import comtypes.gen.Word > except: > comtypes.client.GetModuleContaining('Word.Application') > import comtypes.gen.Word > > Right now what I am doing is: > word_app = comtypes.client.CreateObject('Word.Application') > import comtypes.gen.Word > > But it gives problems if I want to move creation of word_app in a function.
No, that's not possible (at least not easily, if at all). There is no general way to find the type library belonging to a COM object. What you can do is to find out the libid and version numbers of the typelibrary, and pass them to comtypes.client.GetModule. For me, this works: import comtypes.client comtypes.client.GetModule(("{00020905-0000-0000-C000-000000000046}", 8, 0, 1033)) import comtypes.gen.Word The magic numbers used in the call to GetModule are from the comtypes.gen.Word file, once it has been created. Thomas ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ comtypes-users mailing list comtypes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/comtypes-users