This question already has an answer here:
- Use 'import module' or 'from module import'? 13 answers
I'm wondering if there's any difference between the code fragment
from urllib import request
and the fragment
import urllib.request
or if they are interchangeable. If they are interchangeable, which is the "standard"/"preferred" syntax (if there is one)?
Thanks!
You are using Python3 were urllib in the package. Both forms are acceptable and no one form of import is preferred over the other. Sometimes when there are multiple package directories involved you may to use the former
from x.y.z.a import s
In this particular case with urllib package, the second way
import urllib.request
and use ofurllib.request
is how standard library uniformly uses it.