【问题标题】:Translating Python 2 code to Python 3将 Python 2 代码转换为 Python 3
【发布时间】:2013-06-21 10:43:53
【问题描述】:

谁能帮我在不使用 2to3 工具的情况下将这个 python 2 代码翻译成 python 3 吗?

import urllib2, cookielib
self.cj = cookielib.MozillaCookieJar(self.cookie_file)
self.opener = urllib2.build_opener(
            urllib2.HTTPRedirectHandler(),
            urllib2.HTTPHandler(debuglevel=0),
            urllib2.HTTPSHandler(debuglevel=0),
            urllib2.HTTPCookieProcessor(self.cj)
        )

【问题讨论】:

    标签: python-2.7 python-3.x urllib2 cookielib python-2to3


    【解决方案1】:

    我自己通过 Python 文档得到了答案:

    import http.cookiejar
    import urllib.request
    self.cj = http.cookiejar.MozillaCookieJar(self.cookie_file)
    self.opener = urllib.request.build_opener(
                urllib.request.HTTPRedirectHandler(),
                urllib.request.HTTPHandler(debuglevel=0),
                urllib.request.HTTPSHandler(debuglevel=0),
                urllib.request.HTTPCookieProcessor(self.cj)
            )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-12
      • 2016-10-19
      • 2023-03-20
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多