如何在 python-3 中导入 urlparse?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48072619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:31:18  来源:igfitidea点击:

How can i import urlparse in python-3?

pythonpython-3.ximportimporterrorurlparse

提问by Mohamed Mahdi

I would like to use urlparse. But python3.4.1 is not finding the module.

我想用urlparse. 但是python3.4.1没有找到模块。

I do import urlparse, but it gives me this error

我这样做import urlparse,但它给了我这个错误

importError: no 'module' named ulrparse

回答by Abhijit

The urlparse in Python 2.7.11 was renamed to urllib.parse in Python 3. So, if you have a code such from urlparse import urljoin, I suggest you change it to from urllib.parse import urljoin

Python 2.7.11 中的 urlparse 在 Python 3 中重命名为 urllib.parse。因此,如果您有这样的代码from urlparse import urljoin,我建议您将其更改为from urllib.parse import urljoin

回答by Mureinik

As noted in urlparse's documentation:

正如urlparse文档中所述

NoteThe urlparsemodule is renamed to urllib.parsein Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

注意urlparse模块urllib.parse在 Python 3 中重命名为。 2to3 工具将在将源转换为 Python 3 时自动调整导入。

I.e., just use urllib.parseinstead:

即,只需使用urllib.parse

import urllib.parse