python2 "from urllib import quote" 對應 python3 "from urllib import parse"
urillb2在python3中的變化。
在Pytho2.x中使用import urllib2——-對應的,在Python3.x中會使用import urllib.request,urllib.error。
在Pytho2.x中使用import urllib——-對應的,在Python3.x中會使用import urllib.request,urllib.error,urllib.parse
在Pytho2.x中使用import urlparse——-對應的,在Python3.x中會使用import urllib.parse。
在Pytho2.x中使用import urlopen——-對應的,在Python3.x中會使用import urllib.request.urlopen。
在Pytho2.x中使用import urlencode——-對應的,在Python3.x中會使用import urllib.parse.urlencode。
在Pytho2.x中使用import urllib.quote——-對應的,在Python3.x中會使用import urllib.request.quote。
在Pytho2.x中使用cookielib.CookieJar——-對應的,在Python3.x中會使用http.CookieJar。
在Pytho2.x中使用urllib2.Request——-對應的,在Python3.x中會使用urllib.request.Request。
需求: 将python3 代碼中urllib 子產品對應到python2 記錄如下:
python2 -> python3
from urllib import quote -> from urllib import parse
urllib.quote -> parse.quote
------------------------------------------------------------------------------------------------------------------------------
import urlparse -> from urllib.parse import urlparse / import urllib.parse
urlparse.urlparse -> urlparse
----------------------------------------------------------------------------------------------------------------------------------------
import urllib2 -> import urllib.request
urllib2.Request -> urllib.request.Request