#运行以下程序:
#! /usr/bin/env python
#coding =utf-8
File = open (' All_hanzi.txt ', ' WB ')
Listhz = []
N=0
For ch in xrange (0x4e00, 0X9FA6):
Print UNICHR (CH),
File.write (UNICHR (CH)) #此行出错. Correct: File.write (UNICHR (CH). Encode (' GBK ')) encode (' GBK ') encode ' utf-8 ' string encoded as ' GBK '
n = n+1
if (n%50==0):
print ' \ n '
File.write (' \ n ')
Print n
#报错: unicodeencodeerror: ' ASCII ' codec can ' t encode characters in position 0-1: Ordinal not in range (128)
#代码参考: http://www.cnblogs.com/mmix2009/p/3229787.html python print all Chinese characters
The role of Decode is to convert other encoded strings into Unicode encodings, such as Str1.decode (' gb2312 '), to convert gb2312 encoded string str1 into Unicode encoding.
The role of encode is to convert Unicode encoding into other encoded strings, such as Str2.encode (' gb2312 '), to convert Unicode encoded string str2 to gb2312 encoding
Reference: http://www.cnblogs.com/bluescorpio/p/3594359.html
Python's maddening coding problem