现在的位置: 首页 > 综合 > 正文

001_020 Python 使用Unicode来处理国际化文本

2018年02月15日 ⁄ 综合 ⁄ 共 315字 ⁄ 字号 评论关闭

代码如下:

#encoding=utf-8
print '中国'

#使用Unicode来处理国际化文本 

#方案  编码转换ANSI为Unicode后处理
print 'abc 中国'
print unicode('abc 中国')
print type('abc')
print type( unicode('abc 中国'))
print type( 'abc'+ unicode('abc 中国')) #Python 默认转化方式 :ANSI + UNICODE = UNICODE

#建议 读入写入外部文件(File web and so on)时候确定好编码 ,即IO操作的时候

打印结果如下:

中国
abc 中国
abc 中国
<type 'str'>
<type 'unicode'>
<type 'unicode'>

抱歉!评论已关闭.