Welcome Guest.   Make a donation to an author on the site October 22, 2014, 08:44:13 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2014! Download dozens of custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Unicode string works in web based Python shell but not on desktop?  (Read 1750 times)
daddydave
Supporting Member
**
Posts: 818



see users location on a map View Profile Give some DonationCredits to this forum member
« on: June 02, 2012, 12:07:43 PM »

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.

 


Logged
mahesh2k
Supporting Member
**
Posts: 1,408



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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.

Logged
daddydave
Supporting Member
**
Posts: 818



see users location on a map View Profile Give some DonationCredits to this forum member
« 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.

Formatted for Python with the GeSHI Syntax Highlighter [copy or print]
  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:33 AM by daddydave » Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.036s | Server load: 0.08 ]