Dynamic Import with sub module

Douglas Garstang doug.garstang at gmail.com
Sat May 23 12:03:19 EDT 2015


All,

Can someone tell me how the following statement:

import slice_fablib_common.common as common

would be replicated with __import__ or import_module?

I'm using fabric and I want the module when imported to appear in the
namespace (which fabric shows as a task), in this case, as 'common.chef'.
With the import statement it works. However, I'm trying to load the modules
dynamically, and I just cannot work out what combination of options when
used with dynamic imports will get me to 'common.chef'.

When I get that to work, I'd like to go one step further as well. If I have
modules called slice_fablib_webapp.webapp.deploy and
slice_fablib_webapp.webapp.info, I'd like to import them as webapp.deploy
and webapp.info.

I suppose the webapp piece is a bit redundant. If I removed it, and ended
up with slice_fablib_webapp.deploy and slice_fablib_webapp.info, I'd like
to import them so that they still appear in fabric's name space as
webapp.deploy and webapp.info.

Thanks,
Doug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150523/3af5246c/attachment.html>


More information about the Python-list mailing list