Summarizing Import Statements for Packages
00:00 As a rule of thumb, the same guidelines for importing names from modules apply to importing modules from packages. So you should stick with keeping your imports as explicit as possible so that the modules and names imported into the calling module have the appropriate context.
This way when you encounter names from the imported module, there’s no question where those names come from, but sometimes package and module names are long, and you find yourself typing something like
<package>.<module> over and over again in your code.
Then you could use the
from <package> import <module> format, which allows you to skip the package name and import just the module name into the calling module’s namespace. With an
import statement like this, you can just type
<module>.<name> to access a name from the module.
If you want to import multiple modules from one package, then you can list them in one line saying,
from mypackage import module1, module2, and later then in your code, you would call
module2 directly without the
mypackage part for it.
Become a Member to join the conversation.