[Tutor] Problem with input() and unicode string
Mark Tolonen
metolone+gmane at gmail.com
Thu Jul 29 05:09:21 CEST 2010
"Alan Gauld" <alan.gauld at btinternet.com> wrote in message
news:i2pqps$fps$1 at dough.gmane.org...
>
> "Alex" <abccbg at yahoo.co.uk> wrote
>
>> The first print statement works as expected, both in IDLE and when
>> double-clicking the file for a console view.
>> The second one works in IDLE, but just flashes by when double-clicking
>> the file,
>> due to an error report I can't see.
>
> So run it from a Console prompt and you will then be able to see the
> error.
> That should help you debug it.
Try:
import sys
year = raw_input(u'Introduce el año:'.encode(sys.stdout.encoding))
Without the explicit encoding I got a UnicodeError due to using the 'ascii'
codec.
Interesting that 'print' uses the console encoding for Unicode strings, but
input() and raw_input() don't for their prompts.
You may still get a Unicode error if your console encoding doesn't support
the characters you are trying to print, but it worked on my US Windows
'cp437' console.
-Mark
More information about the Tutor
mailing list