Search code examples
pythonshellpython-idlepythoncom

Pythoncom error IDLE (PumpMessage)


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?


Solution

  • 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 running click.py.