help wanted regarding displaying Japanese characters in a GUI using QT and python

Serge Orlov Serge.Orlov at gmail.com
Thu Apr 20 03:43:44 EDT 2006


prats wrote:
> Hi all,
> this is in continuation to my previous post.
> The text I want to display is (in base64 encoding):

> This text contains both english and japanese characters i.e first few
> english characters followed by some japanese characters.
>
> the decoded_string variable contains the first few english characters
> and then all junk characters, which I guess are the "ISO-2022-JP"
> encoded characters.

You guess is wrong. Save you data in a file

 "
import base64
bytes = base64.decodestring(encoded_string)
f = open("jp.txt","wb")
f.write(bytes)
f.close()
"
start Firefox, set View->Encoding->Auto-detect->Japanese and open
jp.txt. Now open menu View->Encoding and see that you data is encoded
in shift-jis encoding. To work with non-ascii character you need to
convert your text to unicode:

text = bytes.decode("shift-jis")

That's it. As David already said, you need to keep your text in
unicode.

> Do I need to change any system settings for that purpose.
> I am using windows XP and I have Japanese fonts installed
> in my PC. I have also set the default font as japanese.

AFAIK you _only_ need to turn on "Install files for Asian languages" in
regional settings.  You don't need to mess with default font. The
following code works perfectly in IDLE on windows xp english edition:

"
import base64
bytes = base64.decodestring(encoded_string)
print bytes.decode("shift-jis")
"




More information about the Python-list mailing list