Python win32com不知道模块名称 [英] Python win32com don't know name of module
问题描述
当我查看pythonwin中的COM浏览器时,我正在寻找python Zune(Windows媒体东西)api.我找到了一个叫做ZuneWmdu类型库(1.0)的东西. 我在该lib上使用了makepy,它生成了一个文件
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
在
python 2.7.3\Lib\site-packages\win32com\gen_py
我不知道该怎么传递
win32com.client.gencache.EnsureDispatch('???')
我尝试致电
win32com.client.gencache.EnsureDispatch('9FE20C0581CE46D79C56FD97A865BBB8')
导致异常(pywintypes.com_error)
Resulting in an exception (pywintypes.com_error)
(.py文件的x0x1x0部分似乎无关)
(The x0x1x0 part of the .py file seemed unrelated)
我也尝试过
win32com.client.gencache.GetModuleForCLSID('9FE20C05-81CE-46D7-9C56-FD97A865BBB8')
and
win32com.client.gencache.GetModuleForProgID('9FE20C0581CE46D79C56FD97A865BBB8')
两者都不返回. 我被困在这里,我需要找到该库的名称(对于iTunes,您可以调用:
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')
) 或如何使用GUID调用模块
for example) or how to call the module with the GUID
甚至有人告诉我我做错了什么事.
Or even someone to tell me that I'm doing something completely wrong.
推荐答案
可以在生成的文件的注释中找到CoClass的名称(它们基于pythoncom.ProgIDFromCLSID
的信息).
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
).
我没有Zune,但是例如,如果我跑步
I don't have Zune but, if, for instance I run
win32com.client.gencache.EnsureModule('{420B2830-E718-11CF-893D-00A0C9054228}', 0, 1, 0)
这将生成一个名为420B2830-E718-11CF-893D-00A0C9054228x0x1x0.py
的文件,从中可以找出相关名称:
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'
这篇关于Python win32com不知道模块名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!