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


Groups > comp.lang.python > #78888

Re: how to add custom importer after the normal imports

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '2.7': 0.14; '*before*': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:after': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'wed,': 0.18; 'implementing': 0.19; 'seems': 0.21; 'example': 0.22; 'import': 0.22; 'install': 0.23; 'header :User-Agent:1': 0.23; 'alternate': 0.24; 'earlier': 0.24; 'versions': 0.24; 'question': 0.24; 'equivalent': 0.26; 'skip:_ 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; "i'm": 0.30; "skip:' 10": 0.31; 'allows': 0.31; 'this.': 0.32; 'received:fr': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'could': 0.34; 'problem': 0.35; 'anybody': 0.35; 'add': 0.35; 'there': 0.35; 'entry': 0.36; 'thanks': 0.36; 'hi,': 0.36; 'project': 0.37; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'ian': 0.60; 'first': 0.61; 'such': 0.63; 'answer.': 0.68; 'default': 0.69; 'received:109': 0.72; 'end.': 0.84; 'gelonida': 0.84; 'subject:add': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Gelonida N <gelonida@gmail.com>
Subject Re: how to add custom importer after the normal imports
Date Thu, 09 Oct 2014 14:51:17 +0200
References <m1353n$dpu$1@ger.gmane.org> <CALwzidnxJs8U+vsG7b6=W8TnRRHROBo0UMQc_uFqjx_t-5Fgkw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 1-75-190-109.dsl.ovh.fr
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <CALwzidnxJs8U+vsG7b6=W8TnRRHROBo0UMQc_uFqjx_t-5Fgkw@mail.gmail.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.14713.1412859107.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412859107 news.xs4all.nl 2906 [2001:888:2000:d::a6]:42342
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78888

Show key headers only | View raw


On 10/9/2014 12:44 AM, Ian Kelly wrote:
> On Wed, Oct 8, 2014 at 4:53 AM, Gelonida N <gelonida@gmail.com> wrote:
>> Hi,
>>
>>
>> I just read about sys.meta_path, which allows to install custom importers
>> *BEFORE* the default importers.
>>
>> However I have a use case where I would like to add a custom importer
>> *AFTER* all other import methods have failed.
>>
>> Does anybody know how to do this.
>>
>> One way of implementing this would be to add the default importer as first
>> entry in sys.meta_path. My only problem is, that I don't know how to create
>> a 'default-importer', such that I can add it into sys.meta_path
>
> As of CPython 3.3 the default importers are already in sys.meta_path,
> so you could just add your custom importer to the end. If you need to
> support earlier versions or alternate implementations then this may
> not be reliable.
>
thanks for your answer.

I'm using Puthon 2.7 for the given project and there sys.meta_path is [].

Just for fun I started Python3.3 and looked at it's meta_path, which 
contained for example _frozen_importlib.PathFinder

Unfortunately python 2.7 does not seem to have the package _frozen_importlib

So now the question seems to boil down to looking for the 2.7 equivalent 
of python 3.3's _frozen_importlib.PathFinder

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: how to add custom importer after the normal imports Gelonida N <gelonida@gmail.com> - 2014-10-09 14:51 +0200

csiph-web