Issue
In many of my python modules, I am using
from itertools import izip_longest
But now I am moving my codebase to Py3 (compatible with Py2 at the same time). And in Py3 izip_longest is renamed to zip_longest. One answer to fix this is recommended in Failing to import itertools in Python 3.5.2, i.e. to change import statement to following.
try:
# Python 3
from itertools import zip_longest as izip_longest
except ImportError:
# Python 2
from itertools import izip_longest
However, changing this in 20+ modules looks a bit odd to me. What is the neat way of doing this?
Solution
You can wrap that exact code inside a module of your own, say itertools_compat.py
, and just write
from itertools_compat import izip_longest
wherever you need this function.
Answered By - Thomas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.