I have a module which is split roughly in half between utility type functions and core api functions. I need to have all of them in __all__ in order to have help() be useful, and also to specify which of the many functions/classes/etc in the module are for external use, but I also want to support from mymodule import * as a way to get just the core functionality into other modules. Is there a way to do that?
I have a module which is split roughly in half between utility type functions
Share
Almost. While you can’t have
__all__do double duty in this way, you can add your own virtual api module which can then be imported…Then in the other modules instead of
from mymodule import *you can dofrom mymodule.api import *to get just the desired subset while still keeping everything in a single module.Note:
from ... import *is not usually good practice, and should be used with great care and only with modules/packages that explicity state that they have been designed with such usage in mind.