|
大小: 441
备注:
|
大小: 1628
备注:
|
| 删除的内容标记成这样。 | 加入的内容标记成这样。 |
| 行号 1: | 行号 1: |
| Python库: * ["PythonImageLibrary中文手册"] Python的编码处理技术 对于中文用户,特别需要关注Python的编码技术. 列举一些常用的技巧。 {{{ chr(i) 将一个0到255的整数转换为一个字符. ord(c) 返回单个字符c的整数顺序值.普通字符返回[0,255]中的一个值,Unicode字符返回 [0,65535]中的一个值 unichr(i) 将一个0到65535的整数转换为一个Unicode字符 }}} * 代码中的编码设置,应该在代码最初两行内包含: {{{ # -*- coding: gb18030 -*- }}} * 获得/设置系统的缺省编码 {{{ sys.getdefaultencoding() sys.setdefaultencoding('utf-8') }}} * 获得文件系统的文件名的编码 {{{ sys.getfilesystemencoding() }}} * 获得当前终端的输入、输出编码 {{{ sys.stdout.encoding sys.stdin.encoding }}} * 编码转换(先转换为unicode,再转换为具体的编码),有两种方法: {{{ unicode('abc', 'mbcs').encode('utf-8') 'abc'.decode('mbcs').encode('utf-8') }}} |
|
| 行号 2: | 行号 44: |
| * [http://diveintopython.org/ Dive Into Python(较老的版本有中文翻译)] | * [http://diveintopython.org/ Dive Into Python] * [http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/html/toc/index.html dive into python最新中文版] |
Python库:
["PythonImageLibrary中文手册"]
Python的编码处理技术
对于中文用户,特别需要关注Python的编码技术. 列举一些常用的技巧。
chr(i) 将一个0到255的整数转换为一个字符. ord(c) 返回单个字符c的整数顺序值.普通字符返回[0,255]中的一个值,Unicode字符返回 [0,65535]中的一个值 unichr(i) 将一个0到65535的整数转换为一个Unicode字符
- 代码中的编码设置,应该在代码最初两行内包含:
# -*- coding: gb18030 -*-
- 获得/设置系统的缺省编码
sys.getdefaultencoding()
sys.setdefaultencoding('utf-8')- 获得文件系统的文件名的编码
sys.getfilesystemencoding()
- 获得当前终端的输入、输出编码
sys.stdout.encoding
sys.stdin.encoding- 编码转换(先转换为unicode,再转换为具体的编码),有两种方法:
unicode('abc', 'mbcs').encode('utf-8')
'abc'.decode('mbcs').encode('utf-8')学习资料
[http://diveintopython.org/ Dive Into Python]
[http://www.woodpecker.org.cn/obp/diveintopython-zh-5.4/zh-cn/dist/html/toc/index.html dive into python最新中文版]
[http://www.python.org/ Python官方站点]
[http://python.cn/ Python中文社区]
[http://groups.google.com/group/comp.lang.python Python讨论组comp.lang.python]
[http://www.ibiblio.org/obp/thinkCSpy/ How to Think Like a Computer Scientist (Learning with Python)]
[http://pine.fm/LearnToProgram/ Learn to Program]