Removed Areas > Python
Unicode string works in web based Python shell but not on desktop?
(1/1)
daddydave:
Any idea why I can create a Unicode string in the Python shell on a Silverlight-based Python on the web but not in IDLE or any other Python shell on my desktop? I am using Google IME to type in both cases.
mahesh2k:
I am using Python 2.7.3 on Ubuntu 12.04 Precise and it seems to be working for me. I guess it could be windows issue. I used google transliterate for the string.
daddydave:
Found the fix and it works.
I notice the indentation is screwed up in stackoverflow -- I put the encoding = 'utf-8' line in line with the try and except preceding it.
This seems to have something to do with the Windows default encoding for stdout not being UTF-8.
--- Code: Python ---encoding = "ascii"if sys.platform == 'win32': # On Windows, we could use "mbcs". However, to give the user # a portable encoding name, we need to find the code page try: encoding = locale.getdefaultlocale()[1] codecs.lookup(encoding) except LookupError: pass encoding = 'utf-8'
Navigation
[0] Message Index
Go to full version