将Python 2代码翻译成Python 3

时间:2013-06-21 10:43:53

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

有人可以帮助我在不使用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)
        )

1 个答案:

答案 0 :(得分:0)

我通过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)
        )