我正在尝试将第三方库从Python 2导入Python3。这是代码:
#
# python2.3 urllib.basejoin does not remove current directory ./
# from path and this causes problems on subsequent basejoins.
#
basejoin = urllib.basejoin
if sys.version_info[0:2] < (2, 4, 0, 'final', 0)[0:2]:
#basejoin = lambda base,url: urllib.basejoin(base,url.lstrip('./'))
token = './'
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
我收到此错误
AttributeError: module 'urllib' has no attribute 'basejoin'
最佳答案
这在Python 3.5上对我有用:
from urllib3.packages.six.moves.urllib.parse import urljoin
basejoin = urljoin
关于python - 如何在Python 3中使用urllib中的basejoin,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59224704/