Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79807
| Date | 2014-10-27 22:55 +0000 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: different behavior from idle/pycharm and shell |
| References | <4417873a-f05f-43b9-9803-1226b1b4ddda@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15244.1414450531.18130.python-list@python.org> (permalink) |
On 2014-10-27 22:38, kiuhnm03@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? > You didn't say whether you're using Python 2 or Python 3, but it looks like you're using Python 3. There are 2 forms of the MessageBox function, one with the suffix 'A', which uses bytestrings, and one with the suffix 'W', which uses Unicode strings. In Python 3, the str class is a Unicode string, so you'll want the MessageBoxW function: from ctypes import * user32 = windll.user32 user32.MessageBoxW(0, 'ok', 'ok', 0) Also, the msvcrt.printf function expects a bytestring.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
different behavior from idle/pycharm and shell kiuhnm03@yahoo.it - 2014-10-27 15:38 -0700
Re: different behavior from idle/pycharm and shell sohcahtoa82@gmail.com - 2014-10-27 15:49 -0700
Re: different behavior from idle/pycharm and shell MRAB <python@mrabarnett.plus.com> - 2014-10-27 22:55 +0000
Re: different behavior from idle/pycharm and shell kiuhnm03@yahoo.it - 2014-10-27 16:14 -0700
csiph-web