Unicode problem 
Author Message
 Unicode problem

I'm writing a script that translates romaji to the appropriate hiragana or
katakan characters. This is Japanese, btw.

From the unicode website, I find that the character code for the hiragana
"NA" is "306a" (JIS). I know it outputs as ? (JIS).

**So how do I get from "306a" to ? ??? **

In Javascript, document.write("\u306a") outputs ? correctly.

When I try that in python (print u"\u306a"), I get the error:
  UnicodeError: ASCII encoding error: ordinal not in range(128)

I've also tried printing u"\u0030\u006a" and  u"\30\6a", but those give me
the wrong thing.

All the docs I've read only deal with Latin encoding, which fall in the
0-127 range nicely. And they deal with mostly u"??" to u"\344\366\374",
instead of the other way around.

Please help. Sorry if this is long. I'm trying to avoid people screaming
RTFM.

Jinushaun
_________________________________________________________________
Get your FREE download of MSN Explorer at http://www.*-*-*.com/



Thu, 27 Nov 2003 04:03:39 GMT  
 Unicode problem

Quote:

> From the unicode website, I find that the character code for the
> hiragana "NA" is "306a" (JIS). I know it outputs as (JIS).

> **So how do I get from "306a" to ??? **

Python doesn't currently come with the necessary codecs for Japanese,
including Shift-JIS.  You can download them from:

    http://pseudo.grad.sccs.chukyo-u.ac.jp/~kajiyama/python/

Once you have them, you can encode the Unicode character as a
Shift-JIS bytestream:

Quote:
>>> na = u'\u306a'
>>> na.encode('japanese.shift_jis')
'\202\310'
>>> print na.encode('japanese.shift_jis')


OK, I made the last line up - my xterm is configured for ISO-8859-1,
not Shift JIS.

--
         Carey Evans  http://home.clear.net.nz/pages/c.evans/

            "Quiet, you'll miss the humorous conclusion."



Thu, 27 Nov 2003 18:18:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Unicode problem from SQL Server DB

2. Suspected Unicode problem when reading from excell

3. Python Unicode problem

4. Win32com and unicode problems - ordinal not in range(128)

5. Win32net.NetServerEnum Unicode problem

6. Unicode problem.... as always

7. unicode problems

8. Unicode problem under IDLE on win32

9. xml and unicode problems

10. Unicode problem

11. Unicode problem... arises with py2exe

12. Suspected Unicode problem when reading text from Excell

 

 
Powered by phpBB® Forum Software