topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 5:25 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Unicode string works in web based Python shell but not on desktop?  (Read 5422 times)

daddydave

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 867
  • test
    • View Profile
    • Donate to Member
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.

 Screenshot - 6_2_2012 , 12_36_31 PM.png



mahesh2k

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,426
    • View Profile
    • Donate to Member
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

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 867
  • test
    • View Profile
    • Donate to Member
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 [Select]
  1. encoding = "ascii"
  2. if sys.platform == 'win32':
  3.     # On Windows, we could use "mbcs". However, to give the user
  4.     # a portable encoding name, we need to find the code page
  5.     try:
  6.         encoding = locale.getdefaultlocale()[1]
  7.         codecs.lookup(encoding)
  8.     except LookupError:
  9.         pass
  10.     encoding = 'utf-8'
« Last Edit: June 03, 2012, 09:53 AM by daddydave »