Python win32com don't know name of module

自作多情 提交于 2019-12-10 14:39:04

问题


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.


回答1:


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'


来源:https://stackoverflow.com/questions/17225798/python-win32com-dont-know-name-of-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!