Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'insert': 0.05; 'interpreter': 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; "'.py'": 0.16; 'docs.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'scripts.': 0.16; 'subject:after': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'seems': 0.21; 'example': 0.22; 'import': 0.22; 'header :User-Agent:1': 0.23; 'directory.': 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; 'code': 0.31; 'equivalent.': 0.31; 'option': 0.32; 'another': 0.32; 'received:fr': 0.33; 'skip:_ 10': 0.34; 'subject:the': 0.34; 'add': 0.35; 'there': 0.35; 'thanks': 0.36; 'project': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'ian': 0.60; 'kind': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'answer.': 0.68; 'deeply': 0.69; 'default': 0.69; 'received:109': 0.72; 'expose': 0.84; 'subject:add': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: Re: how to add custom importer after the normal imports Date: Fri, 10 Oct 2014 13:46:48 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 1-75-190-109.dsl.ovh.fr User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412941636 news.xs4all.nl 2841 [2001:888:2000:d::a6]:45999 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78944 On 10/09/2014 04:14 PM, Ian Kelly wrote: >> I have a use case where I would like to add a custom importer *AFTER* all other import methods have failed. > > On Oct 9, 2014 6:53 AM, "Gelonida N" > wrote: > > 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 > > There is no equivalent. Prior to 3.3 that code was buried deeply in the > interpreter and not available to scripts. The reason for the change was > to expose more of the import machinery for exactly this kind of > manipulation. > > > Thanks for your answer. That's a pity. So the only option I had is to write another custom importer, that mimics as much functionality of the default importer as is necessary so that I can insert it before the otjer custom importers. In my current case this would be to import '.py' files from the current working directory. Will try to find some docs.