File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,10 +37,10 @@ in Python 2 you can import it from ``__future__``.
3737 # Output:
3838
3939 from __future__ import print_function
40- print
40+ print ( print )
4141 # Output: <built-in function print>
4242
43- **Using ``as`` in imports **
43+ **Dealing with module renaming **
4444
4545First tell me how you import packages in your script ? Most of us do
4646this :
@@ -64,9 +64,9 @@ code below :
6464.. code :: python
6565
6666 try :
67- import urllib.request as urllib_request # for python 3
67+ import urllib.request as urllib_request # for python 3
6868 except ImportError :
69- import urllib2 as urllib_request # for python 2
69+ import urllib2 as urllib_request # for python 2
7070
7171 So let me explain the above code a little. We are wrapping our importing
7272code in a try except clause. We are doing it because in python2 there is
@@ -111,6 +111,7 @@ functionality in Python 2. For instance we have:
111111- singledispatch ``pip install singledispatch ``
112112- pathlib ``pip install pathlib ``
113113
114+
114115I am sure there are a lot of other methods and tricks which can be used
115116to make you code compatible with both of these Python series. This was
116117just to give you some ideas.
You can’t perform that action at this time.
0 commit comments