On Sat, 19 Mar 2005 22:21:36 0800, Python Leo <
Python.leo@gmail.com>
Wrote:
>>> Unicode ('Chinese ",' cp936 ')
> u '/ u4e2d / u6587'
>>> Print Unicode ('Chinese ",' cp936 ')
> Chinese
>>>
> Who talks about why this is different? If you want to output Chinese to a file, how should you deal with?
Under the interaction interface, you will output an expr () of the return value after you knockerel, if the return value is None, no results are output. therefore:
Unicode ('Chinese', 'CP936') will return a Unicode object, U '/ U4E2D / U6587' is an expr (Unicode ('Chinese', 'CP936') returns.
Unicode ('Chinese', 'CP936') This statement will print out words "Chinese", return NONE, so no longer output anything.
That is, U '/ U4E2D / U6587' is output by the interactive interface, and the word "Chinese" is your command output.
To output Chinese to the file, you only need to encode Chinese Unicode to String with the encoding format you need, then use file.write () or print.
>> f. If your Chinese string is originally string format, write directly to the file.
Read after ME:
String object is just a bunch of bytes, only confirmed its encoding, it can be called "character" string
>>> Unicode ('Chinese ",' cp936 ')
> u '/ u4e2d / u6587'
This treatment is Python automatically. It is displayed in the data stored inside the computer. This is the real content!
>>> Print Unicode ('Chinese ",' cp936 ')
> Chinese
This is printed, it is to see. The operating system is converted into a corresponding font based on compilation. If you have done a GUI program, you can understand that you can draw Chinese characters on the screen.
>>>