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
urllib went through some changes in Python3 and can now be imported from the parse submodule
If you need to handle both Python 2.x and 3.x you can catch the exception and load the alternative.
You could also use the python compatibility wrapper six to handle this.
In Python 3.x, you need to import
urllib.parse.quote
:According to Python 2.x
urllib
module documentation: