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'
这很奇怪,因为在 shell 中导入 pythoncom 并编写命令 pythoncom.PumpMessages() 之后,它运行没有任何问题。这个问题该如何解决呢?
Trying to run this script:
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()
I receive an error:
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'
It's strange, because after importing a pythoncom in a shell and writing the command pythoncom.PumpMessages() it runs without any problem. How could be this issue solved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您在该文件夹中有一个文件
pythoncom.py
,该文件正在导入,而不是真正的 pythoncom 模块。尝试将该文件重命名为其他名称,然后运行 click.py
。It looks like you've got a file
pythoncom.py
in that folder, which is being imported instead of the real pythoncom module. Try renaming that file to something else, then runningclick.py
.