Python win32com 不知道模块的名称 [英] Python win32com don't know name of module

查看:30
本文介绍了Python win32com 不知道模块的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 pythonwin 中查看 COM 浏览器时,我正在寻找一个 python Zune(Windows 媒体的东西)api.我找到了一个叫做 ZuneWmdu 类型库 (1.0) 的东西.我在那个库上使用了 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')

两者都返回 None.我被困在这里,我需要找到库的名称(对于 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆