Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • September 02, 2015, 09:51:08 AM
  • Proudly celebrating 10 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 2084 times)

daddydave

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 822
    • 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


If bad things happen to other people, it's karma. If bad things happen to me, it's kismat!

mahesh2k

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,412
    • View Profile
    • Donate to Member
Re: Unicode string works in web based Python shell but not on desktop?
« Reply #1 on: June 02, 2012, 01:29:34 PM »
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: 822
    • View Profile
    • Donate to Member
Re: Unicode string works in web based Python shell but not on desktop?
« Reply #2 on: June 02, 2012, 02:11:28 PM »
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
  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'
  11.  
If bad things happen to other people, it's karma. If bad things happen to me, it's kismat!
« Last Edit: June 03, 2012, 09:53:33 AM by daddydave »