2011-11-20 104 views
0

试图运行此脚本:Pythoncom错误IDLE(PumpMessage)

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' 

这很奇怪,因为在外壳导入pythoncom和写入命令后pythoncom .PumpMessages()它运行没有任何问题。这个问题怎么能解决?

回答

3

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

+1

omg,你说的没错。什么是致命的失败。 – Stanyko