Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106436
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Robin Becker <robin@reportlab.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: 2.7 source import in python 3.x |
| Date | Mon, 4 Apr 2016 12:51:27 +0100 |
| Lines | 46 |
| Message-ID | <mailman.14.1459770692.32530.python-list@python.org> (permalink) |
| References | <5702418D.6080906@chamonix.reportlab.co.uk> <ndtibp$e5p$1@ger.gmane.org> <5702553F.2070303@chamonix.reportlab.co.uk> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de +RW39rV/NAA41qBFiKF7oARvcHHfUjUsC9gRCnXw3pJQ== |
| 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.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'sys': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spec': 0.09; 'subject:2.7': 0.09; 'python': 0.10; 'subject:python': 0.14; 'above)': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:import': 0.16; 'tokenize': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'helper': 0.18; 'stick': 0.18; 'bit': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; "skip:' 10": 0.28; 'purposes.': 0.29; 'guess': 0.31; 'skip:s 30': 0.31; 'maybe': 0.33; 'traceback': 0.33; '(for': 0.34; 'file': 0.34; 'skip:c 30': 0.35; 'ahead': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'received:109': 0.75; '.....': 0.76; '3.4': 0.84; 'becker': 0.84; 'otten': 0.84; 'subject:source': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | 109.174.168.73 |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <ndtibp$e5p$1@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| 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> |
| X-Mailman-Original-Message-ID | <5702553F.2070303@chamonix.reportlab.co.uk> |
| X-Mailman-Original-References | <5702418D.6080906@chamonix.reportlab.co.uk> <ndtibp$e5p$1@ger.gmane.org> |
| Xref | csiph.com comp.lang.python:106436 |
Show key headers only | View raw
On 04/04/2016 12:15, Peter Otten wrote: .......... > > In the example section they have (for 3.4 and above) > > spec = importlib.util.spec_from_file_location(module_name, file_path) > module = importlib.util.module_from_spec(spec) > spec.loader.exec_module(module) > > The importlib with all its factories is a bit intimidating; perhaps it's > best to stick with imp.load_source() and wait for some simple helper > functions to appear... .... maybe two steps ahead :( when I execute the example with python 3.4.2 > C:\code\hg-repos\reportlab>cat tmp\t1.py > import importlib.util > import sys > > # For illustrative purposes. > import tokenize > file_path = tokenize.__file__ > module_name = tokenize.__name__ > > spec = importlib.util.spec_from_file_location(module_name, file_path) > module = importlib.util.module_from_spec(spec) > spec.loader.exec_module(module) > # Optional; only necessary if you want to be able to import the module > # by name later. > sys.modules[module_name] = module > > C:\code\hg-repos\reportlab>\python34\python tmp\t1.py > Traceback (most recent call last): > File "tmp\t1.py", line 10, in <module> > module = importlib.util.module_from_spec(spec) > AttributeError: 'module' object has no attribute 'module_from_spec' The example does work in python 3.5.0 so I guess the docs are a bit misleading. -- Robin Becker
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: 2.7 source import in python 3.x Robin Becker <robin@reportlab.com> - 2016-04-04 12:51 +0100
csiph-web