How do I import all the submodules of a Python namespace package?

The "from module import *" statement is used to import all submodules from a Python package/module. For example, if you want to import all modules from your module(say nyModule) and do not want to prefix "myModule." while calling them, you can do it as follows:

>>> from myModule import *

Note that for any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy to get to the point where you think you don't use the import any more but it's extremely difficult to be sure. It basically clutters the namespace and leaves you with lesser options to name things in your module.

Updated on: 01-Oct-2019


Kickstart Your Career

Get certified by completing the course

Get Started