を使いたいのですurllib.quote()
が、python (python3) がモジュールを見つけられません。次のようなコードがあるとします。
print(urllib.quote("châteu", safe=''))
urllib.quote をインポートするにはどうすればいいですか?
import urllib
またはimport urllib.quote
両方を与える
AttributeError: 'module' object has no attribute 'quote'
私が困惑しているのはurllib.request
、import urllib.request
ベストアンサー1
Python 3.xでは、インポートする必要がありますurllib.parse.quote
:
>>> import urllib.parse
>>> urllib.parse.quote("châteu", safe='')
'ch%C3%A2teu'
によるとPython 2.xurllib
モジュールのドキュメント:
注記
この
urllib
モジュールは Python 3 で複数の部分に分割され、 、 、 に名前が変更されurllib.request
ましurllib.parse
たurllib.error
。