Python – How to Import * with __import__

importpython

What's the best approach to execute the following using __import__ so that I may dynamically specify the module?

from module import *

Best Answer

The only way I found:

module = __import__(module, globals(), locals(), ['*'])
for k in dir(module):
    locals()[k] = getattr(module, k)