compat.py |
|
---|---|
Compatibility helpers to bridge the differences between Python 2 and Python 3. Similar in purpose to |
|
Imports |
import sys
|
Module Exports |
__all__ = ['py3', 'pypy', 'unicode', 'str']
|
Version Detection |
py3 = sys.version_info > (3, )
pypy = hasattr(sys, 'pypy_version_info')
|
Builtins Compatibility |
|
Use of the |
if py3:
unicode = str
str = bytes
items = dict.items
else:
unicode = unicode
str = str
items = dict.iteritems
|
File-Like String Handling |
try:
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
except ImportError:
from io import StringIO
|