Dynamically import specific names from a module vs importing full module

Random832 random832 at fastmail.com
Mon Aug 22 16:59:46 EDT 2016


On Mon, Aug 22, 2016, at 16:21, Malcolm Greene wrote:
> Python 3.5: Is there a way to dynamically import specific names from a
> module vs importing the full module?
> 
> By dynamic I mean via some form of importlib machinery, eg. I'm looking
> for the dynamic "from <module> import <name>" equivalent of "import
> <module>"'s importlib.import_module.

You do know that "from <module> import <name>" still loads the whole
module into sys.modules, right? And you're free to assign the result
from importlib.import_module to a local variable and delete it once
you've gotten the names you want out of it.



More information about the Python-list mailing list