Python:导入urllib.quote [英] Python: Importing urllib.quote

查看:1875
本文介绍了Python:导入urllib.quote的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 urllib.quote()。但是python(python3)没有找到模块。
假设,我有这行代码:

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=''))

如何导入urllib.quote?

How do I import urllib.quote?

import urllib
import urllib.quote both give

import urllib or import urllib.quote both give

AttributeError: 'module' object has no attribute 'quote'

让我感到困惑的是 urllib.request 可通过 import urllib.request 访问

What confuses me is that urllib.request is accessible via import urllib.request

推荐答案

在Python 3.x中,您需要导入 urllib.parse.quote

In Python 3.x, you need to import urllib.parse.quote:

>>> import urllib.parse
>>> urllib.parse.quote("châteu", safe='')
'ch%C3%A2teu'

根据 Python 2.x urllib 模块文档

According to Python 2.x urllib module documentation:


注意

urllib 模块已拆分为多个部分,并在Python 3中重命名为
urllib.request urllib.parse urllib.error

The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error.

这篇关于Python:导入urllib.quote的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆