2. six
• Utilities for wrapping between Python 2 and 3
• Multiplication is more powerful
• “Five” has already been snatched away by the
Zope Five project
http://pythonhosted.org/six/
10. Python 3
>>> text = u'Lorem ipsum' ! # Python 3.3+!
!
>>> isinstance(text, unicode)!
Traceback (most recent call last):!
File "<stdin>", line 2, in <module>!
NameError: name 'unicode' is not defined
11. Python 3
>>> text = 'Lorem ipsum'!
>>> isinstance(text, basestring)!
Traceback (most recent call last):!
File "<stdin>", line 2, in <module>!
NameError: name 'basestring' is not defined
12. six
>>> import six!
>>> text = 'Lorem ipsum'!
>>> isinstance(text, six.string_types)!
True!
>>> text = u'Lorem ipsum' # Python 3.3+!
>>> isinstance(text, six.string_types)!
True
13. six
Python 2
Python 3
class_types
type, types.ClassType
type
integer_types
long, int
int
string_types
basestring
str
text_type
unicode
str
binary_type
str, bytes (2.7)
bytes
MAXSIZE
sys.maxsize (2.6+)
sys.maxsize