Six 提供了一些简单的工具用来封装 Python 2 和 Python 3 之间的差异性,示例代码:[code]import six
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)[/code]主页:http://packages.python.org/six/
下载:http://pypi.python.org/pypi/six/
来自:开源中国社区