[Q] ImportError by __import__() on Python >= 3.4

Makoto Kuwata kwa at kuwata-lab.com
Wed Jun 8 05:52:05 EDT 2016


On Tue, Jun 7, 2016 at 7:28 AM, Michael Selik <michael.selik at gmail.com>
wrote:

> On Thu, Jun 2, 2016 at 10:06 AM Makoto Kuwata <kwa at kuwata-lab.com> wrote:
>
>> I have a trouble around __import__().
>>
>
> The docs for __import__ strongly recommend that you use importlib instead
> https://docs.python.org/3.5/library/importlib.html#importlib.import_module
>
> The docs for ``importlib.import_module`` suggest that you use
> ``invalidate_caches`` if you are importing dynamically generated files.
>
> https://docs.python.org/3.5/library/importlib.html#importlib.invalidate_caches
>
> I think you'll find this fixes your bug.
>

Great!
I replaced '__import__()' in my code  with 'importlib.invalidate_cache();
importlib.import_module()'
and found it worked very well.
Thank you very much.

--
regards,
makoto


More information about the Python-list mailing list