Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41122
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:134': 0.05; '-1)': 0.07; '[],': 0.07; 'arguments': 0.07; 'works.': 0.07; 'before.': 0.09; 'imported': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'script,': 0.09; 'subject:module': 0.09; ':-)': 0.13; 'globals(),': 0.16; 'message-id:@post.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:accessing': 0.16; 'subject:created': 0.16; 'thread.': 0.16; 'circular': 0.17; 'load': 0.19; 'module': 0.19; 'import': 0.21; 'thanks.': 0.21; 'defined': 0.22; "i've": 0.23; 'header:User-Agent:1': 0.26; 'guess': 0.27; 'header:X-Complaints- To:1': 0.28; 'writes:': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'function': 0.30; 'sense': 0.31; 'url:python': 0.32; 'file': 0.32; 'to:addr:python-list': 0.33; 'project': 0.34; 'there': 0.35; 'received:org': 0.36; 'url:org': 0.36; 'loaded': 0.36; 'url:library': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'two': 0.37; 'usual': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'think': 0.40; "you'll": 0.62; 'situation': 0.62; 'ever': 0.63; 'more': 0.63; 'url:functions': 0.84; 'tricky': 0.91; 'angel': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Kene Meniru <kemeniru@gmail.com> |
| Subject | Re: Running external module and accessing the created objects |
| Date | Tue, 12 Mar 2013 13:28:45 +0000 (UTC) |
| References | <mailman.3110.1362798411.2939.python-list@python.org> <513aecd3$0$6512$c3e8da3$5496439d@news.astraweb.com> <khlr16$lr0$1@ger.gmane.org> <513E7B6B.5070608@davea.name> <khm025$1hl$1@ger.gmane.org> <513E8ECC.20805@davea.name> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | sea.gmane.org |
| User-Agent | Loom/3.14 (http://gmane.org/) |
| X-Loom-IP | 134.192.3.12 (Mozilla/5.0 (X11; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0 Iceweasel/19.0.2) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3230.1363095584.2939.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363095584 news.xs4all.nl 6868 [2001:888:2000:d::a6]:58464 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41122 |
Show key headers only | View raw
Dave Angel <davea <at> davea.name> writes: > > The __import__() function is defined > http://docs.python.org/2/library/functions.html#__import__ > Thanks. The name of the imported file will change with each user and for each project so according to the this reference using this in my situation makes sense. > appname = "myapp" > usermodule = __import__(appname, globals(), locals(), [], -1) > > And now you can use usermodule as though you had imported it in the > usual way. > Thanks. This worked! I was using __import__ without the other arguments before. I guess did not think it will work :-) > As for my other caveat, I've said it before in this thread. Make sure > you don't ever load a module by more than one name, or you'll end up > with a mess. And that includes the original script, which is loaded by > the name '__main__' > > You also should avoid any circular import, as it can be very tricky to > deal with them. > The two programs are separate, there is no fear of a circular import. Also, I need only a function to get access to the objects in the other module so the import is inside the function... no fear of ending up in a mess. Thanks. I guess this makes more sense than execfile and it works.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-08 22:06 -0500
Re: Running external module and accessing the created objects Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-09 08:03 +0000
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 06:05 -0500
Re: Running external module and accessing the created objects Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-09 11:34 +0000
Re: Running external module and accessing the created objects Chris Angelico <rosuav@gmail.com> - 2013-03-09 22:47 +1100
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-09 07:02 -0500
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 10:34 -0500
Re: Running external module and accessing the created objects Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-09 08:51 -0800
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 12:21 -0500
Re: Running external module and accessing the created objects Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-09 10:33 -0800
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-09 11:12 -0500
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 11:56 -0500
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-09 12:20 -0500
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 12:39 -0500
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-09 13:18 -0500
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-11 19:57 -0400
Re: Running external module and accessing the created objects Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-11 23:40 -0700
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-11 20:48 -0400
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-11 21:23 -0400
Re: Running external module and accessing the created objects Kene Meniru <Kene.Meniru@illom.org> - 2013-03-11 21:58 -0400
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-11 22:16 -0400
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-11 22:11 -0400
Re: Running external module and accessing the created objects Michael Torrie <torriem@gmail.com> - 2013-03-11 22:05 -0600
Re: Running external module and accessing the created objects Dave Angel <davea@davea.name> - 2013-03-12 07:20 -0400
Re: Running external module and accessing the created objects Kene Meniru <kemeniru@gmail.com> - 2013-03-12 13:38 +0000
Re: Running external module and accessing the created objects Kene Meniru <kemeniru@gmail.com> - 2013-03-12 13:28 +0000
csiph-web