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

 

相关文章:

  • 2021-12-02
  • 2018-06-13
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
猜你喜欢
  • 2021-07-12
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
相关资源
相似解决方案