Python comtypes - '_Dispatch' object is not callable

杀马特。学长 韩版系。学妹 提交于 2019-12-11 18:29:13

问题


I have been using the comtypes module for Python to automate Photoshop, but I am getting a TypeError when I try to execute commands on windows8.

These same commands have been working fine on windows7.

This an example of the code I am using:

from comtypes.client import CreateObject

psApp = CreateObject("Photoshop.Application")

#Create a new document- this is where it bombs out!
psApp.Documents.Add(1024, 1024, 72, 'new_source_texture', 2, 1, 1)

And this is the Traceback I get:

Traceback (most recent call last):
    File "test.py", line 9, in <module>
    psApp.Documents.Add(1024, 1024, 72, 'new_source_texture', 2, 1, 1)
TypeError: '_Dispatch' object is not callable

I suspect it has something to do with comtypes returning the wrong type of object, but I'm pretty newb so if anyone can point me in the right direction I would really appreciate it!

Thanks!


回答1:


It seems this is a compatibility issue with Windows 8. Once I set the Python command line to execute with windows XP compatibility mode the comtypes module worked as expected.

This same fix also applies to the win32com module, which I tried but experienced similar difficulties with.

To set compatibility modes in windows 8, you can follow these steps:

  1. Go to your control panel.
  2. Click on the 'Programs' category.
  3. Click on 'Run programs made for previous versions of windows'
  4. Step through the troubleshooter, selecting the Python command line as the target program.


来源:https://stackoverflow.com/questions/14861258/python-comtypes-dispatch-object-is-not-callable

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