Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91137

Re: Dynamic Import with sub module

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 <doug.garstang@gmail.com>
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&gt;': 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 <CANmEAK9K1_KJ20AmQ9vnSURK1tqR0rJ0NX5Fj-tNxJFiZfaA_A@mail.gmail.com>
References <CANmEAK9K1_KJ20AmQ9vnSURK1tqR0rJ0NX5Fj-tNxJFiZfaA_A@mail.gmail.com>
Date Sat, 23 May 2015 09:08:38 -0700
Subject Re: Dynamic Import with sub module
From Douglas Garstang <doug.garstang@gmail.com>
To "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.280.1432397321.17265.python-list@python.org> (permalink)
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

Show key headers only | View raw


[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


Thread

Re: Dynamic Import with sub module Douglas Garstang <doug.garstang@gmail.com> - 2015-05-23 09:08 -0700

csiph-web