Beware of circular imports!
I just spent 24 hours of my life debugging this so watch out. Circular imports do some very strange things. In my case we have some singelton instances that suddenly stopped being singeltons (i.e. they re-instantiated on every run) all because someone added a circular import. So now you know.
It doesn't support file paths. It does support package names, but it doesn't really do what you expect: __import__('X.Y.Z') will indeed import the X, X.Y, and X.Y.Z modules and install them in sys.modules, but the function returns the X package module instead of the Z module.
Beware of circular imports!
I just spent 24 hours of my life debugging this so watch out. Circular imports do some very strange things. In my case we have some singelton instances that suddenly stopped being singeltons (i.e. they re-instantiated on every run) all because someone added a circular import. So now you know.
It doesn't support file paths. It does support package names, but it doesn't really do what you expect: __import__('X.Y.Z') will indeed import the X, X.Y, and X.Y.Z modules and install them in sys.modules, but the function returns the X package module instead of the Z module.
Also see: http://effbot.org/zone/import-string.htm
"The Module Documentation Tells You To Use from-import"
Examples of this would include everything in __future__.