zoukankan      html  css  js  c++  java
  • python2 、python3 urllib 模块一些特别的对应关系

    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

  • 相关阅读:
    推荐一个SAM文件中flag含义解释工具--转载
    字节码技术
    Jconsole工具检测堆内存变化的使用
    观察者模式
    装饰器模式(IO流案例)
    JVM垃圾收集器
    内存溢出与内存泄漏区别
    栈溢出
    内存溢出
    JVM参数调优
  • 原文地址:https://www.cnblogs.com/rockstics/p/11929505.html
Copyright © 2011-2022 走看看