Six提供了Python 2和Python 3的兼容库
来源:互联网 发布:淘宝网触屏版不能操作 编辑:程序博客网 时间:2024/06/18 04:15
地址:http://packages.python.org/six/
Six provides simple utilities for wrapping over differences between Python 2 and Python 3.
Six can be downloaded on PyPi. Its bug tracker and code hosting is on BitBucket.
The name, “six”, comes from the fact that 2*3 equals 6. Why not addition? Multiplication is more powerful, and, anyway, “five” has already been snatched away.
Indices and tables
Index
Search Page
Package contents
six.PY3
A boolean indicating if the code is running on Python 3.
Constants
Six provides constants that may differ between Python versions. Ones ending _types are mostly useful as the second argument to isinstance or issubclass.
six.class_types
Possible class types. In Python 2, this encompasses old-style. and new-style. classes. In Python 3, this is just new-styles.
six.integer_types
Possible integer types. In Python 2, this is long() and int(), and in Python 3, just int().
six.string_types
Possible types for text data. This is basestring() in Python 2 and str() in Python 3.
six.text_type
Type for representing (Unicode) textual data. This is unicode() in Python 2 and str() in Python 3.
six.binary_type
The maximum size of a container. This is equivalent to sys.maxsize in Python 2.6 and later (including 3.x). Note, this is temptingly similar to, but not the same as sys.maxint in Python 2. There is no direct equivalent to sys.maxint in Python 3 because its integer type has no limits aside from memory.
Here’s example usage of the module:
def dispatch_types(value):
if isinstance(value, six.integer_types):
handle_integer(value)
elif isinstance(value, six.class_types):
handle_class(value)
elif isinstance(value, six.string_types):
handle_string(value)
Six provides simple utilities for wrapping over differences between Python 2 and Python 3.
Six can be downloaded on PyPi. Its bug tracker and code hosting is on BitBucket.
The name, “six”, comes from the fact that 2*3 equals 6. Why not addition? Multiplication is more powerful, and, anyway, “five” has already been snatched away.
Indices and tables
Index
Search Page
Package contents
six.PY3
A boolean indicating if the code is running on Python 3.
Constants
Six provides constants that may differ between Python versions. Ones ending _types are mostly useful as the second argument to isinstance or issubclass.
six.class_types
Possible class types. In Python 2, this encompasses old-style. and new-style. classes. In Python 3, this is just new-styles.
six.integer_types
Possible integer types. In Python 2, this is long() and int(), and in Python 3, just int().
six.string_types
Possible types for text data. This is basestring() in Python 2 and str() in Python 3.
six.text_type
Type for representing (Unicode) textual data. This is unicode() in Python 2 and str() in Python 3.
six.binary_type
Type for representing binary data. This is str() in Python 2 and bytes() in Python 3.
The maximum size of a container. This is equivalent to sys.maxsize in Python 2.6 and later (including 3.x). Note, this is temptingly similar to, but not the same as sys.maxint in Python 2. There is no direct equivalent to sys.maxint in Python 3 because its integer type has no limits aside from memory.
Here’s example usage of the module:
CODE:
import sixdef dispatch_types(value):
if isinstance(value, six.integer_types):
handle_integer(value)
elif isinstance(value, six.class_types):
handle_class(value)
elif isinstance(value, six.string_types):
handle_string(value)
0 0
- Six提供了Python 2和Python 3的兼容库
- 编写兼容 Python 2 和 Python 3 的代码
- Python 的 six模块简介
- python内置map和six.moves.map的区别
- python同时兼容2和3的几个技巧
- python 内置map()和six.moves.map()区别
- some tips about python Six
- python提供读了文件更好的方法
- Python下的scipy,matplotlib,Numpy,six安装
- python中的six.moves模块的下载函数urlretrieve
- 在Python标准库的json包中,提供了JSONEncoder和JSONDecoder两个类来实现Json字符串和dict类型数据的互相转换。
- 在Python标准库的json包中,提供了JSONEncoder和JSONDecoder两个类来实现Json字符串和dict类型数据的互相转换。
- 提供python接口有用的库
- Microsoft 提供了 Python Tools for Visual Studio (PTVS) 这款功能强大的插件 Python IDE
- Python提供的基本数据类型
- 安装python及一些库文件(numpy+scipy+matplotlib+scikit-image+six)时遇到的问题
- python setuptools six pip easy_install 安装冲突
- Mac OSX 升级python six模块版本
- OpenCV Mat
- 【c语言】为下面的函数原型编写函数定义,这个字符串参数必须包含一个或者多个数字,函数应该把这些数字字符转换为整数并返回这个整数。
- sql: postgreSQL sql script
- 【C语言】为下面的函数原型编写函数定义: int ascii_to_integer(char *str); 这个字符串参数必须包含一个或者多个数字,函数应该把这些数字字符转换为整数并返回这个整数。
- 自定义View之onMeasure()
- Six提供了Python 2和Python 3的兼容库
- hdu 2612 Find a way(双向bfs)
- 士兵杀敌(二)(树状数组之插点问线问题)
- 为什么要用补码?
- 在IE的document上触发事件问题
- 在openSUSE13.2安装ENVI4.7/IDL7.1
- android AsyncTask 请求与实现
- 使用js改变DOM样式的三种方式 - style属性
- 动态页面SEO优化