Thursday, December 17, 2009

PythonWin and Python Ctypes

Ran into a situation when using PythonWin by Mark Hammond - btw its a really nice IDE with syntax highlighting and debugging capabilities :) kudos!. So what happened is this:
When i ran this simple piece of code against the PythonWin and a normal Python session from the Windows command prompt, i get two results.
>>> from ctypes import *
>>> cdll.msvcrt.printf(c_char_p('hello world'))
When i ran it against the PythonWin, i was only seeing the string '11' returned and in the other case i was seeing 'hello world11' which is what i expected. For some reason unknown to me at this point in time, PythonWin is capturing the result of the call to printf() whilst ignoring/hid the I/O conducted by printf(). I think it is a bug and i've filed it <- in case you're interested - but in a nutshell its basically the group of I/O functions sys.stdout etc being overridden

Of course i'm not going to dismiss PythonWin (i think its a great job at that, thanks Mark) but i just thought that you might like to know incase you bumped into this.


0 comments: