python 3.5.2
code 1
import urllib
s = urllib.parse.quote('"')
print(s)
it gave this error:
AttributeError: module 'urllib' has no attribute 'parse'
code 2
from urllib.parse import quote
# import urllib
# s = urllib.parse.quote('"')
s = quote('"')
print(s)
it works...
code3
from flask import Flask
# from urllib.parse import quote
# s = quote('"')
import urllib
s = urllib.parse.quote('"')
print(s)
it works,too. because of flask?
Why I don't have the error anymore? is it a bug ?
import urllib.parse
. I would assume thatFlask
also importsurllib.parse
, and that's why your third example works. – Bootblack$ ipython Python 3.7.1 (default, Dec 13 2018, 11:43:05) Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import urllib In [2]: urllib.parse.quote('foo bar') Out[2]: 'foo%20bar'
. I'm unsure why it works there. – Partlyimport urllib.parse
? Why can't we justimport urllib
? Is this way of importing applicable to every Python3 module? – Jumpy