Python:导入 urllib.quote [英] Python: Importing urllib.quote
问题描述
我想使用 urllib.quote()
.但是 python (python3) 没有找到模块.假设,我有这行代码:
print(urllib.quote("châteu", safe=''))
如何导入 urllib.quote?
import urllib
或import urllib.quote
都给
AttributeError: 'module' 对象没有属性 'quote'
令我困惑的是,urllib.request
可以通过 import urllib.request
在 Python 3.x 中,您需要导入 urllib.parse.quote
:
根据 Python 2.x urllib
模块文档:><块引用>
注意
urllib
模块在 Python 3 中被拆分为多个部分并重命名为urllib.request
、urllib.parse
和 urllib.error
.
I would like to use urllib.quote()
. But python (python3) is not finding the module.
Suppose, I have this line of code:
print(urllib.quote("châteu", safe=''))
How do I import urllib.quote?
import urllib
or
import urllib.quote
both give
AttributeError: 'module' object has no attribute 'quote'
What confuses me is that urllib.request
is accessible via import urllib.request
In Python 3.x, you need to import urllib.parse.quote
:
>>> import urllib.parse
>>> urllib.parse.quote("châteu", safe='')
'ch%C3%A2teu'
According to Python 2.x urllib
module documentation:
NOTE
The
urllib
module has been split into parts and renamed in Python 3 tourllib.request
,urllib.parse
, andurllib.error
.
这篇关于Python:导入 urllib.quote的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!