[Tutor] Problem with input() and unicode string

Timo timomlists at gmail.com
Wed Jul 28 18:35:58 CEST 2010


On 28-07-10 18:05, Alex wrote:
> Hello, I have a problem with this code:
> # -*- coding: latin-1 -*-
> year = u'año, ò, ó, ç'
> print year
> year = input(u'Introduce el año:')
> print year
> raw_input()
> 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.
I don't have a solution, but call your script from the commandline to 
stay open after exceptions. Or try some things in the Python interactive 
prompt:

 >>> year = input(u'Introduce el año:')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in 
position 14: ordinal not in range(128)

Cheers,
Timo


> I believe the problem is that input prompt doesn't support unicode 
> strings, which means I can't use my language for prompts?
> Could someone please tell me how to fix it or provide a workaround?
> Thanx.
> Using Python 2.7 under win32.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>    



More information about the Tutor mailing list