different behavior from idle/pycharm and shell

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Mon Oct 27 23:49:59 CET 2014

On Monday, October 27, 2014 3:38:31 PM UTC-7, kiuh... at yahoo.it wrote:
> Consider this code:
> ---
> from ctypes import *
> user32 = windll.user32
> user32.MessageBoxA(0, 'ok', 'ok', 0)
> ---
> If I run it in idle or from pycharm, the messagebox shows 'o' instead of 'ok', but if I run it from shell, it shows 'ok' like it should.
> The same happens with msvcrt.printf().
> Why?

If I had to take a guess, in the shell, it is encoding the string characters as single bytes as expected, but in Idle or PyCharm, it is encoding them as WCHARs, which are two-bytes wide.

Two things to try:

1. Change the call to MessageBoxW and see if it works in Idle/PyCharm.  Note that this will probably break the call from the shell.
2. Try a string longer than two characters and see what you get.

More information about the Python-list mailing list