Making httplib and urlparse modules compatible with both Python 2 & 3
There are some changes in Python 3 especially some packages are renamed such as httplib -> http.client and urlparse -> urllib.parse. Below is a way to make those 2 work in both Python 2 and 3:
import sys
if sys.version_info[0] < 3:
import httplib
import urlparse
else:
import http.client as httplib
import urllib.parse as urlparse
Note: 'sys.version_info[0] < 3' is used to check the current running python version.
import sys
if sys.version_info[0] < 3:
import httplib
import urlparse
else:
import http.client as httplib
import urllib.parse as urlparse
Note: 'sys.version_info[0] < 3' is used to check the current running python version.
Comments
Post a Comment