how can i write a hello world in chinese with python

K

kernel1983

I'm try to build a bundle on OS X, so I write a simple python script
for a test:

#!/usr/bin/env python
import EasyDialogs
EasyDialogs.Message("Hello,Mac!")


This runs OK,but when I try to replace "Hello,Mac!" with chinese, it
can't be display rightly.
Then I tried some way else:

#!/usr/bin/env python
import EasyDialogs
EasyDialogs.Message("\xe4\xb8\xad")

It doesn't work!

As I know mac is unicode based,how can I display chinese on the screen?
 
K

kernel1983

and I tried unicode and utf-8
I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not
to use

Anyone knows about the setting in the python code file?
Maybe python doesn't know I'm to use chinese?!
 
D

Dennis Lee Bieber

and I tried unicode and utf-8
I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not
to use
"unicode" is a term covering many sins. "utf-8" is a specification
for encoding elements of specific unicode characters using 8-bit
elements (I believe by using certain codes x00 to x7F alone as "normal",
and then x80 to xFF to represent an "escape" to higher [16-bit] element
sets).

"\xEF\xBB\xBF" is just a byte string with no identifier of what
encoding is in use (unless the first one or two are supposed to be
BOM)... In the "Windows: Western" character set, it is equivalent to
small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western
Europe, those same bytes represent an
acute-accent/double-down&left-box-drawing/solid-down&left

I've not done any unicode work (iso-latin-1, or subset thereof, has
done for me). I also don't know Mac's, so I don't know if the windowing
API has specific calls for Unicode data... But you probably have to
encode or decod that bytestring into some compatible unicode
representation.

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
L

Leo Kislov

kernel1983 said:
and I tried unicode and utf-8

How did you try unicode? Like this? :

EasyDialogs.Message(u'\u4e2d')
I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not
to use

Anyone knows about the setting in the python code file?
Maybe python doesn't know I'm to use chinese?!

It depends on how EasyDialogs works. And by the way, when you say utf-8
encoded text is not displayed correctly, what do you actually see on
the screen?

-- Leo
 
J

John Machin

Leo said:
How did you try unicode? Like this? :

EasyDialogs.Message(u'\u4e2d')


It depends on how EasyDialogs works. And by the way, when you say utf-8
encoded text is not displayed correctly, what do you actually see on
the screen?

There is a Windows version of EasyDialogs -- unfortunately it appears
not to support Unicode, even for the most simple case.

This works:
| >>> EasyDialogs.Message('fubar')
but this doesn't:
| >>> EasyDialogs.Message(u'fubar')

The title of the window is empty, the text consists of only 'f", and
there is no OK button.
Not very robust.
 
K

Kevin Walzer

kernel1983 said:
I'm try to build a bundle on OS X, so I write a simple python script
for a test:

#!/usr/bin/env python
import EasyDialogs
EasyDialogs.Message("Hello,Mac!")


This runs OK,but when I try to replace "Hello,Mac!" with chinese, it
can't be display rightly.
Then I tried some way else:

#!/usr/bin/env python
import EasyDialogs
EasyDialogs.Message("\xe4\xb8\xad")

It doesn't work!

As I know mac is unicode based,how can I display chinese on the screen?
EasyDialogs is an *ancient* module on OS X--it may not support unicode.
Try posting to the MacPython list, someone there can verify this.

--Kevin
 
M

MRAB

Dennis said:
and I tried unicode and utf-8
I tried to both use unicode&utf-8 head just like "\xEF\xBB\xBF" and not
to use
"unicode" is a term covering many sins. "utf-8" is a specification
for encoding elements of specific unicode characters using 8-bit
elements (I believe by using certain codes x00 to x7F alone as "normal",
and then x80 to xFF to represent an "escape" to higher [16-bit] element
sets).

"\xEF\xBB\xBF" is just a byte string with no identifier of what
encoding is in use (unless the first one or two are supposed to be
BOM)... In the "Windows: Western" character set, it is equivalent to
small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western
Europe, those same bytes represent an
acute-accent/double-down&left-box-drawing/solid-down&left

I've not done any unicode work (iso-latin-1, or subset thereof, has
done for me). I also don't know Mac's, so I don't know if the windowing
API has specific calls for Unicode data... But you probably have to
encode or decod that bytestring into some compatible unicode
representation.
When you save a textfile as UTF-8 in Notepad.exe (Windows) it puts the
bytestring "\xEF\xBB\xBF" at the start to indicate that it's UTF-8 and
not ANSI (ie 8-bit characters). The bytes are actually the BOM
bytestring "\xFE\xFF" encoded in UTF-8.
 
K

kernel1983

thanks everyone
maybe this simple API doesn't fit the Chinese display
but thanks everybody!

At least I've got that what bundles is and maybe I can use Python to
write program

Dennis said:
On 12 Dec 2006 23:40:41 -0800, "kernel1983" <[email protected]>
declaimed the following in gmane.comp.python.general:
"unicode" is a term covering many sins. "utf-8" is a specification
for encoding elements of specific unicode characters using 8-bit
elements (I believe by using certain codes x00 to x7F alone as "normal",
and then x80 to xFF to represent an "escape" to higher [16-bit] element
sets).
"\xEF\xBB\xBF" is just a byte string with no identifier of what
encoding is in use (unless the first one or two are supposed to be
BOM)... In the "Windows: Western" character set, it is equivalent to
small-i-diaeresis/right-guillemot/upside-down? () In MS-DOS: Western
Europe, those same bytes represent an
acute-accent/double-down&left-box-drawing/solid-down&left
I've not done any unicode work (iso-latin-1, or subset thereof, has
done for me). I also don't know Mac's, so I don't know if the windowing
API has specific calls for Unicode data... But you probably have to
encode or decod that bytestring into some compatible unicode
representation.When you save a textfile as UTF-8 in Notepad.exe (Windows) it puts the
bytestring "\xEF\xBB\xBF" at the start to indicate that it's UTF-8 and
not ANSI (ie 8-bit characters). The bytes are actually the BOM
bytestring "\xFE\xFF" encoded in UTF-8.
 
S

Sime

As I know mac is unicode based,how can I display chinese on the screen?

Did you tried to define Python source code encoding?

#!/usr/bin/env python
# -*- coding: utf-8 -*-

print 'ãã‚ã‹ãŒã'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top