Pythoncom错误空闲(PumpMessage)

Pythoncom错误空闲(PumpMessage),python,shell,python-idle,pythoncom,Python,Shell,Python Idle,Pythoncom,正在尝试运行此脚本: import pythoncom, pyHook def OnMouseEvent(event): # called when mouse events are received print 'MessageName:',event.MessageName print 'Message:',event.Message print 'Time:',event.Time print 'Window:',event.Window

正在尝试运行此脚本:

import pythoncom, pyHook 

def OnMouseEvent(event):
    # called when mouse events are received
    print 'MessageName:',event.MessageName
    print 'Message:',event.Message
    print 'Time:',event.Time
    print 'Window:',event.Window
    print 'WindowName:',event.WindowName
    print 'Position:',event.Position
    print 'Wheel:',event.Wheel
    print 'Injected:',event.Injected
    print '---'

    # return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseAll = OnMouseEvent
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()
我收到一个错误:

Traceback (most recent call last):
  File "C:\Python26\Test\click.py", line 1, in <module>
    import pythoncom, pyHook
  File "C:\Python26\Test\pythoncom.py", line 13, in <module>
    pythoncom.PumpMessages() #will wait forever
AttributeError: 'module' object has no attribute 'PumpMessages'
回溯(最近一次呼叫最后一次):
文件“C:\Python26\Test\click.py”,第1行,在
导入pythoncom、pyHook
文件“C:\Python26\Test\pythoncom.py”,第13行,在
pythoncom.PumpMessages()将永远等待
AttributeError:“模块”对象没有属性“PumpMessages”

这很奇怪,因为在shell中导入pythoncom并编写命令pythoncom.PumpMessages()后,它运行起来没有任何问题。这个问题如何解决?

看起来您在该文件夹中有一个文件
pythoncom.py
,该文件正在导入,而不是真正的pythoncom模块。尝试将该文件重命名为其他文件,然后运行
click.py

看起来您在该文件夹中有一个文件
pythoncom.py
,该文件正在导入,而不是真正的pythoncom模块。尝试将该文件重命名为其他文件,然后运行
click.py