Given that foo.bar
is a module, what is the difference between
import foo.bar as bar
and
from foo import bar
I'm particularly interested in what lazy importing of modules does to this.
Note: This is not a duplicate of this question .
In the first code line:
import foo.bar as bar
Here you are importing bar
from foo
package but why added as bar
means when you need to access any function func
in that bar
. You have to access like foo.bar.func
but when you added as bar
you just use
bar.func
The same to the line from foo import bar
just importing the bar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.