Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91137
| References | <CANmEAK9K1_KJ20AmQ9vnSURK1tqR0rJ0NX5Fj-tNxJFiZfaA_A@mail.gmail.com> |
|---|---|
| Date | 2015-05-23 09:08 -0700 |
| Subject | Re: Dynamic Import with sub module |
| From | Douglas Garstang <doug.garstang@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.280.1432397321.17265.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Replying to my own message.
I just realised that even the case I thought would work, will not. :(
If I have:
import slice_fablib_common.common as common
I end up with fabric showing me these commands:
Available commands:
common.chef.report
common.chef.run Run the chef client.
common.chef.start Start chef-client service.
common.chef.status Show chef-client service status.
common.chef.stop Stop chef-client service.
However, that's only because slice_fablib_common/common/__init__.py has
'import chef'. I need to be able to individually load sub-modules from
common. I'm essentially loading the entire package here because I need to
put an import for every sub module into __init__.py anyway. :(
Doug.
On Sat, May 23, 2015 at 9:03 AM, Douglas Garstang <doug.garstang@gmail.com>
wrote:
> 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.
>
>
--
Regards,
Douglas Garstang
http://www.linkedin.com/in/garstang
Email: doug.garstang@gmail.com
Cell: +1-805-340-5627
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dynamic Import with sub module Douglas Garstang <doug.garstang@gmail.com> - 2015-05-23 09:08 -0700
csiph-web