Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python win32com don't know name of module

I was looking for a python Zune(The windows media thing) api, when I looked at the COM browser in pythonwin. I found something called ZuneWmdu Type Library (1.0). I used makepy on that lib, it generated a file

9FE20C05-81CE-46D7-9C56-FD97A865BBB8x0x1x0.py 

in

python 2.7.3\Lib\site-packages\win32com\gen_py

I have no idea what to pass into

 win32com.client.gencache.EnsureDispatch('???')

I tried calling

win32com.client.gencache.EnsureDispatch('9FE20C0581CE46D79C56FD97A865BBB8')

Resulting in an exception (pywintypes.com_error)

(The x0x1x0 part of the .py file seemed unrelated)

I tried the same with

win32com.client.gencache.GetModuleForCLSID('9FE20C05-81CE-46D7-9C56-FD97A865BBB8')
and
win32com.client.gencache.GetModuleForProgID('9FE20C0581CE46D79C56FD97A865BBB8')

Both returning None. I'm stuck here, I need to either find what the library is called (for itunes, you'd call:

win32com.client.gencache.EnsureDispatch('iTunes Application')

for example) or how to call the module with the GUID

Or even someone to tell me that I'm doing something completely wrong.

like image 389
Azeirah Avatar asked Jun 21 '13 00:06

Azeirah


1 Answers

The name of the CoClass can be found in the comments of the generated file (where they are based on the information from pythoncom.ProgIDFromCLSID).

I don't have Zune but, if, for instance I run

win32com.client.gencache.EnsureModule('{420B2830-E718-11CF-893D-00A0C9054228}', 0, 1, 0)

this will generate a file called 420B2830-E718-11CF-893D-00A0C9054228x0x1x0.py from which I can dig out the relevant names:

C:\Users\username\AppData\Local\Temp\gen_py\3.6>grep 'known by' *.py
420B2830-E718-11CF-893D-00A0C9054228x0x1x0.py:# This CoClass is known by the name 'Scripting.Dictionary'
420B2830-E718-11CF-893D-00A0C9054228x0x1x0.py:# This CoClass is known by the name 'Scripting.Encoder'
420B2830-E718-11CF-893D-00A0C9054228x0x1x0.py:# This CoClass is known by the name 'Scripting.FileSystemObject'
like image 131
fuglede Avatar answered Oct 19 '22 11:10

fuglede