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


Groups > comp.lang.python > #78944

Re: how to add custom importer after the normal imports

From Gelonida N <gelonida@gmail.com>
Subject Re: how to add custom importer after the normal imports
Date 2014-10-10 13:46 +0200
References <m1353n$dpu$1@ger.gmane.org> <CALwzidnxJs8U+vsG7b6=W8TnRRHROBo0UMQc_uFqjx_t-5Fgkw@mail.gmail.com> <m160c7$ne3$1@ger.gmane.org> <CALwzidmojCE8+_Q34pZdhxhGf3sG9wxer-GEo1PSSy8MF0PsgA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14747.1412941636.18130.python-list@python.org> (permalink)

Show all headers | View raw


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" <gelonida@gmail.com
> <mailto:gelonida@gmail.com>> 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.


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-10 13:46 +0200

csiph-web