Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6100
| References | <BANLkTi=KaLdo28Fo3KhH5bvdtMW8iHmYOw@mail.gmail.com> |
|---|---|
| Date | 2011-05-24 08:42 +1000 |
| Subject | Re: Strange behaviour of input() function (Python 3.2) |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1989.1306190539.9059.python-list@python.org> (permalink) |
On Tue, May 24, 2011 at 1:44 AM, Aleksander Pietkiewicz
<sunrrrise@gmail.com> wrote:
> Hello,
> I have googled your email address, I hope it is not a problem.
> Thank you for your help!
I figured you would get it from my post, but either way works! My
email address is fairly well known. Sorry for the delay in response;
you caught me while I was asleep. :) I'm now responding on-list so
that other people can help.
> I agree that can be very specific bug, I suspect it is matter of coding. I'm
> emailing you a *.py file as you asked and screenshot showing script being
> run.
Unfortunately my Windows install doesn't have internationalization
support, which may be an issue here. I ran your 'couting.py' and got
errors back:
Traceback (most recent call last):
File "foo.py", line 11, in <module>
n=input("Naci\u015bnij Enter aby zako\u0144czy\u0107...")
File "C:\python32\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character '\u015b' in position
4: character maps to <undefined>
So I'm guessing that codepage 437 is just plain wrong. But that
shouldn't affect your system.
> As you can see this problem occurs only with 3rd party software (like Komodo
> Edit).
> In, addition when I'm using Komodo or Notepad++ and input() function, Python
> miscount bytes. See attached.
> Once again thank you for your help!
> Kind regards,
> Aleksander Pietkiewicz
My suspicion here is that your editor is saving using one encoding,
and Python is expecting another. I recommend you put an encoding
marker at the top of your source file:
# coding=utf-8
See http://www.python.org/dev/peps/pep-0263/ for details. With this in
place, you should be able to guarantee that the bytestream is parsed
the same way by editor and interpreter.
Unfortunately that's all I could offer; I was unable to duplicate the
exact problem you were seeing. The contents of 'couting.py' are simple
enough, so I'll paste here in case anyone can spot a problem:
s = (input('Enter something : '))
z = input('Enter something : ')
print('Length of the string s is', len(s))
print('Length of the string z is', len(z))
print(s)
print(z)
Point to note: On my Windows XP, the string lengths are one higher
than expected, and they include a \r at the end. Is there any way that
this could trigger a Unicode parse failure??
Chris Angelico
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Strange behaviour of input() function (Python 3.2) Chris Angelico <rosuav@gmail.com> - 2011-05-24 08:42 +1000
csiph-web