You can name a python module using the __import__

2

I have the following code

__import__('some_module')

And I was wondering if it was possible to do something like this:

__import__('some_module') as some_name

    
asked by anonymous 26.01.2018 / 13:27

1 answer

3

As you have in the question is not, but you can assign the return of __import__ to a var, eg:

mod_alias = __import__('string')

The equivalent of:

import string as mod_alias

In this case mod_alias is your alias.

DEMONSTRATION

    
26.01.2018 / 13:41