Can importlib import more than one module at a time in Python 2.7?

Rob Watts

I need to import two modules (determined at runtime) in the same package and I was wondering if it could be done with one import_module command.

Basically, I want the equivalent of

from some_package import module1, module2

Ways I could do it:

  • Call import_module once for each module
  • Have __init__.py import the two modules, then import the package
  • Use __import__, but this doesn't use importlib and is discouraged by the docs.

There are probably more ways to do it than this. Can it be done with a single call to import_module? Failing that, is there a way to do this that is considered the standard way?

Eugene K

One call? Probably not. You can however do:

for module in modules:
    importlib.import_module(module)

or:

 map(importlib.import_module, module)

Why does it matter if it's more than one call? The internal implementation of all the ways to import is probably serial and individual 'calls' either way.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Error: More than one module matches. Use skip-import option to skip importing the component into the closest module

From Dev

drools: rules executed more than one time

From Dev

python: importlib.import_module("time") but time is not defined globally

From Dev

PHP if character repeated more than one time

From Dev

Can one java executable run more than one loop at the same time

From Dev

How can I scroll more than one object at the same time?

From Dev

Can I use same requestScope more than one time in jsp

From Dev

one() firing more than one time

From Dev

Import a module or add a path one time forever in python

From Dev

Why can't I catch the exception more than one time?

From Dev

Retrieve rows that appears more than one time

From Dev

Python import issue with more than one folders

From Dev

Can a slice iterator be advanced more than one element in constant time?

From Dev

LabView playing more than one sound at the time

From Dev

More than one file in module

From Dev

Allow more than one python threads to use resource at the same time

From Dev

How to load more than one div at a time

From Dev

importlib can't find module

From Dev

Running where() more more than one time

From Dev

Is the following while loop can be run more than one time?

From Dev

Allow more than one python threads to use resource at the same time

From Dev

python: importlib.import_module("time") but time is not defined globally

From Dev

Can importlib import more than one module at a time in Python 2.7?

From Dev

Why can't I catch the exception more than one time?

From Dev

Python import issue with more than one folders

From Dev

why is there more than one python 2 command in ubuntu 12.04?

From Dev

Why I can't reference to WITH expression more than one time?

From Dev

How can I contain more than 2 models in one template?

From Dev

Can I use OpenGL in more than one language at the same time?

Related Related

  1. 1

    Error: More than one module matches. Use skip-import option to skip importing the component into the closest module

  2. 2

    drools: rules executed more than one time

  3. 3

    python: importlib.import_module("time") but time is not defined globally

  4. 4

    PHP if character repeated more than one time

  5. 5

    Can one java executable run more than one loop at the same time

  6. 6

    How can I scroll more than one object at the same time?

  7. 7

    Can I use same requestScope more than one time in jsp

  8. 8

    one() firing more than one time

  9. 9

    Import a module or add a path one time forever in python

  10. 10

    Why can't I catch the exception more than one time?

  11. 11

    Retrieve rows that appears more than one time

  12. 12

    Python import issue with more than one folders

  13. 13

    Can a slice iterator be advanced more than one element in constant time?

  14. 14

    LabView playing more than one sound at the time

  15. 15

    More than one file in module

  16. 16

    Allow more than one python threads to use resource at the same time

  17. 17

    How to load more than one div at a time

  18. 18

    importlib can't find module

  19. 19

    Running where() more more than one time

  20. 20

    Is the following while loop can be run more than one time?

  21. 21

    Allow more than one python threads to use resource at the same time

  22. 22

    python: importlib.import_module("time") but time is not defined globally

  23. 23

    Can importlib import more than one module at a time in Python 2.7?

  24. 24

    Why can't I catch the exception more than one time?

  25. 25

    Python import issue with more than one folders

  26. 26

    why is there more than one python 2 command in ubuntu 12.04?

  27. 27

    Why I can't reference to WITH expression more than one time?

  28. 28

    How can I contain more than 2 models in one template?

  29. 29

    Can I use OpenGL in more than one language at the same time?

HotTag

Archive