Compat¶
compatible data structures, libs, functions for Python 2 and 3.
-
pydu.compat.
PY2
¶ Specify current Python interpreter is Python 2 or 3.
-
pydu.compat.
urlib
(base, url, allow_fragments=True)¶ Same to
urllib
on PY2 orurllib.request
on PY3.
-
pydu.compat.
urlparse
(base, url, allow_fragments=True)¶ Same to
urlparse
on PY2 orurllib.parse
on PY3.
-
pydu.compat.
urljoin
(base, url, allow_fragments=True)¶ Same to
urlparse.urljoin
on PY2 orurllib.parse.urljoin
on PY3.
-
pydu.compat.
iterkeys
(d)¶ Return an iter object of dictionary keys.
-
pydu.compat.
itervalues
(d)¶ Return an iter object of dictionary values.
-
pydu.compat.
iteritems
(d)¶ Return an iter object of dictionary items.
-
pydu.compat.
text_type
¶ The text type is
unicode
on PY2 orstr
on PY3.
-
pydu.compat.
string_types
¶ The string types are
(str, unicode)
on PY2 or(str,)
on PY3.
-
pydu.compat.
strbytes_types
¶ The strbytes(string bytes) types are
(str, unicode, bytes)
on PY2 or(str, bytes)
on PY3.
-
pydu.compat.
numeric_types
¶ The numeric types are
(int, long)
on PY2 or(int,)
on PY3.
-
pydu.compat.
imap
(function, sequence, *sequence_1)¶ Same to
itertools.imap
on PY2 ormap
on PY3.
-
pydu.compat.
reduce
(function, sequence, initial=None)¶ Same to built-in
reduce
on PY2 orfunctools.reduce
on PY3.
-
pydu.compat.
cmp
(x, y)¶ Same to
cmp
on PY2, but implement on PY3.
-
pydu.compat.
has_next_attr
(x)¶ An implementation independent way of checking for next attribute.
-
pydu.compat.
is_iterable
(x)¶ An implementation independent way of checking for iterables.
>>> from pydu.compat import is_iterable >>> is_iterable([]) True >>> is_iterable(1) False