Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'essentially': 0.04; 'works.': 0.07; 'imported': 0.09; 'imports': 0.09; 'namespace': 0.09; 'sub': 0.09; 'subject:module': 0.09; '23,': 0.16; '__init__.py': 0.16; 'doug.': 0.16; 'redundant.': 0.16; 'status.': 0.16; 'subject:sub': 0.16; 'webapp': 0.16; 'wrote:': 0.16; 'have:': 0.18; 'thanks,': 0.19; 'load': 0.20; 'all,': 0.20; 'email addr:gmail.com>': 0.20; 'to:name:python- list@python.org': 0.20; 'work,': 0.21; 'trying': 0.22; 'cell:': 0.22; 'suppose': 0.22; 'am,': 0.23; 'bit': 0.23; '2015': 0.23; 'module': 0.23; 'sat,': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.28; 'options': 0.28; "i'm": 0.29; 'appear': 0.29; 'piece': 0.29; '(which': 0.29; "skip:' 10": 0.30; "i'd": 0.31; 'skip:s 30': 0.31; 'run': 0.32; 'common': 0.33; 'combination': 0.33; 'loading': 0.33; 'case,': 0.34; 'message.': 0.34; 'received:google.com': 0.34; 'to:addr:python-list': 0.35; 'step': 0.36; 'modules': 0.36; 'statement': 0.36; 'subject:: ': 0.37; 'thought': 0.37; 'someone': 0.38; 'space': 0.38; 'end': 0.39; 'to:addr:python.org': 0.39; 'well.': 0.40; 'subject:with': 0.40; 'called': 0.40; 'further': 0.60; 'even': 0.61; 'email:': 0.61; 'entire': 0.61; 'replying': 0.61; 'show': 0.62; 'service.': 0.63; '8bit%:10': 0.64; 'email addr:gmail.com': 0.64; 'here': 0.66; 'url:info': 0.71; '8bit%:27': 0.72; 'subject:Import': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ZKO6+XkGFR3CL2OVTnGXkRNcEKp+Uuus9RO5O9lu/ZA=; b=YkbzHr1A+KV31UHE5Pg8uK9EpnmbhxaoVIK9npYHshFC3LBZmM9Tzla5Yb8SleqSVZ lBo1YrJ2OzPCDsELOfQr+yHGnc4v+U/hWJAaNXssLo0WwfmcFxuypPvciT5PLoD4LJSw m6MhXofeHKutXIvQVtbP6mQbfNj3f6FS3MJ1y9US3Q0gLyQ6HPvqlv/aKYZaqHZkp5QT HvxIm6FHVNKjw+o6KmeuiYT1BN5/DvnBJ0jCoaiWdvFRtuI9rwKbFgLOfNSbXufprXLu vbNyC7WT/hanKTo0nX+QhtCJCY79P3IcHGdxp3qYJJqqBMbfUq63RWneXdyy09R0pKMH Cx7w== MIME-Version: 1.0 X-Received: by 10.112.125.231 with SMTP id mt7mr4011249lbb.113.1432397319018; Sat, 23 May 2015 09:08:39 -0700 (PDT) In-Reply-To: References: Date: Sat, 23 May 2015 09:08:38 -0700 Subject: Re: Dynamic Import with sub module From: Douglas Garstang To: "python-list@python.org" Content-Type: multipart/alternative; boundary=089e01160e66609ca10516c1fda8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 119 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432397321 news.xs4all.nl 2854 [2001:888:2000:d::a6]:54893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91137 --089e01160e66609ca10516c1fda8 Content-Type: text/plain; charset=UTF-8 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 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 --089e01160e66609ca10516c1fda8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 comm= on

I end up with fabric showing me these commands:

Avai= lable commands:

=C2=A0=C2=A0=C2=A0 common.chef.report
=C2=A0=C2= =A0=C2=A0 common.chef.run=C2=A0=C2=A0=C2=A0=C2=A0 Run the chef client.
= =C2=A0=C2=A0=C2=A0 common.chef.start=C2=A0=C2=A0 Start chef-client service.=
=C2=A0=C2=A0=C2=A0 common.chef.status=C2=A0 Show chef-client service st= atus.
=C2=A0=C2=A0=C2=A0 common.chef.stop=C2=A0=C2=A0=C2=A0 Stop chef-cl= ient service.

However, that's only because slice_fablib_co= mmon/common/__init__.py has 'import chef'. I need to be able to ind= ividually load sub-modules from common. I'm essentially loading the ent= ire 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_fabl= ib_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. Howeve= r, I'm trying to load the modules dynamically, and I just cannot work o= ut what combination of options when used with dynamic imports will get me t= o '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 im= port 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&#= 39;s name space as webapp.deploy and webapp.info.

Thanks,
Doug.




--
Regards,

Douglas Garstang
http://www.linkedin.com/in/garstang<= br>Email: doug= .garstang@gmail.com
Cell: +1-805-340-5627
--089e01160e66609ca10516c1fda8--