标签:
>>> from __future__ import division
>>> 5/3
1.6666666666666667
>>> 5/2
2.5
>>> divmod(5, 2)
(2, 1)
>>> round(5/2)
3.0
ord()
能够返回某个字符所对一个的ASCII值(是十进制的),字符a在ASCII中的值是97,空格在ASCII中也有值,是32。
反过来,根据整数值得到相应字符,可以使用chr()。
>>> ord(‘a‘)
97
>>> chr(99)
‘c‘
>>> import sys
>>> sys.getdefaultencoding()
‘ascii‘
>>> sys.setdefaultencoding()
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
sys.setdefaultencoding()
AttributeError: ‘module‘ object has no attribute ‘setdefaultencoding‘
>>> reload(sys)
>>> sys.setdefaultencoding(‘utf-8‘)
"AttributeError: ‘module‘ object has no attribute ‘setdefaultencoding‘" why ???
"""Append module search paths for third-party packages to sys.path."""
* This module is automatically imported during initialization. *
def setencoding():
"""Set the string encoding used by the Unicode implementation.
The default is ‘ascii‘, but if you‘re willing to experiment, you can change this.
"""
encoding = "ascii" # Default value set by _PyUnicode_Init()
def main():
......
# Remove sys.setdefaultencoding() so that users cannot change the
# encoding after initialization. The test for presence is needed when
# this module is run as a script, because this code is executed twice.
if hasattr(sys, "setdefaultencoding"):
del sys.setdefaultencoding
源码参见 https://hg.python.org/cpython/file/2.7/Lib/site.py#l545
编码问题更多可参考 http://www.the5fire.com/unicodeencodeerror-from-future.html
标签:
原文地址:http://www.cnblogs.com/tangkaixin/p/4404668.html