Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64422
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; '21,': 0.07; 'attribute': 0.07; 'subject:file': 0.07; 'subject:into': 0.09; 'subject:module': 0.09; "'__doc__',": 0.16; "'__file__',": 0.16; '-tkc': 0.16; '>on': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'imports': 0.16; 'subject:import': 0.16; 'wrote:': 0.18; 'module': 0.19; 'passing': 0.19; 'work,': 0.20; '>>>': 0.22; 'import': 0.22; 'print': 0.22; '31,': 0.24; 'subject: .': 0.24; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; "doesn't": 0.30; 'work.': 0.31; "skip:' 10": 0.31; 'file': 0.32; '(most': 0.33; 'but': 0.35; 'charset:us-ascii': 0.36; 'january': 0.37; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; "you're": 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'imp': 0.84; 'received:50.22': 0.84 |
| Date | Tue, 21 Jan 2014 09:36:20 -0600 |
| From | Tim Chase <python.list@tim.thechases.com> |
| To | python-list@python.org |
| Subject | Re: import file without .py into another module |
| In-Reply-To | <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> |
| References | <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> <mailman.5786.1390316784.18130.python-list@python.org> <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> |
| X-Mailer | Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| X-Get-Message-Sender-Via | boston.accountservergroup.com: authenticated_id: tim@thechases.com |
| 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 | <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.5787.1390318534.18130.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1390318534 news.xs4all.nl 2897 [2001:888:2000:d::a6]:37874 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:64422 |
Show key headers only | View raw
On 2014-01-21 07:13, kevinbercaw@gmail.com wrote:
>On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote:
>> configModuleObject = imp.load_source(fileName, filePath)
>>
>> imports the module and then binds it to the name
>> configModuleObject,
>>
>> therefore:
>>
>> print configModuleObject.myVar
>
> Yep, I tried that right off as that's how I thought it would work,
> but it doesn't work. Traceback (most recent call last):
> File "mainScript.py", line 31, in <module>
> print configModuleObject.myVar
> AttributeError: 'module' object has no attribute 'myVar'
Check what you're passing for fileName/FilePath:
>>> import imp
>>> with open('demo.txt', 'wb') as f:
... f.write('x = 42\ny = "hello"\n')
...
>>> d = imp.load_source('SomeName', 'demo.txt')
>>> dir(d)
['__builtins__', '__doc__', '__file__', '__name__', '__package__',
'x', 'y']
>>> d.x
42
>>> d.y
'hello'
>>> d.__name__
'SomeName'
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
import file without .py into another module kevinbercaw@gmail.com - 2014-01-21 06:44 -0800
Re: import file without .py into another module MRAB <python@mrabarnett.plus.com> - 2014-01-21 15:06 +0000
Re: import file without .py into another module kevinbercaw@gmail.com - 2014-01-21 07:13 -0800
Re: import file without .py into another module Tim Chase <python.list@tim.thechases.com> - 2014-01-21 09:36 -0600
Re: import file without .py into another module Peter Otten <__peter__@web.de> - 2014-01-21 16:40 +0100
Re: import file without .py into another module kevinbercaw@gmail.com - 2014-01-21 07:50 -0800
Re: import file without .py into another module Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-21 18:10 +0000
Re: import file without .py into another module kevinbercaw@gmail.com - 2014-01-21 07:27 -0800
csiph-web