When using __import__ with a dotted name, something like: somepackage.somemodule, the module returned isn’t somemodule, whatever is returned seems to be mostly empty! what’s going on here?
When using __import__ with a dotted name, something like: somepackage.somemodule , the module returned
Share
From the python docs on
__import__:To paraphrase:
When you ask for
somepackage.somemodule,__import__returnssomepackage.__init__.py, which is often empty.It will return
somemoduleif you providefromlist(a list of the variable names insidesomemoduleyou want, which are not actually returned)You can also, as I did, use the function they suggest.
Note: I asked this question fully intending to answer it myself. There was a big bug in my code, and having misdiagnosed it, it took me a long time to figure it out, so I figured I’d help the SO community out and post the gotcha I ran into here.