import_pkg1.py 310 B

12345678910111213141516
  1. import pkg.mod
  2. print(pkg.__name__)
  3. print(pkg.mod.__name__)
  4. print(pkg.mod.foo())
  5. # Import 2nd time, must be same module objects
  6. pkg_ = __import__("pkg.mod")
  7. print(pkg_ is not pkg.mod)
  8. print(pkg_ is pkg)
  9. print(pkg_.mod is pkg.mod)
  10. # import using "as"
  11. import pkg.mod as mm
  12. print(mm is pkg.mod)
  13. print(mm.foo())