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

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

问题描述

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

print(urllib.quote("châteu", safe=''))

如何导入 urllib.quote?

import urllibimport urllib.quote 都给

AttributeError: 'module' 对象没有属性 'quote'

令我困惑的是,urllib.request 可以通过 import urllib.request

访问

解决方案

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

<预><代码>>>>导入 urllib.parse>>>urllib.parse.quote("châteu", safe='')'ch%C3%A2teu'

根据 Python 2.x urllib 模块文档:><块引用>

注意

urllib 模块在 Python 3 中被拆分为多个部分并重命名为urllib.requesturllib.parseurllib.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 to urllib.request, urllib.parse, and urllib.error.

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

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