Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoidedhttps://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-pythonhttps://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (https://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: https://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila@janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

added 78 characters in body
Source Link
Nihathrael
  • 641
  • 4
  • 12

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's@janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

Using exec() is generally regarded as bad practice (http://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package.

Python 2: https://docs.python.org/2/library/importlib.html

Python 3: https://docs.python.org/3/library/importlib.html#module-importlib

Using it should clean up the rest of the code as well.

You might also be interested in this discussion for more possibilities regarding imports: http://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python

Edit 2: Removed my code example, as @janne-karila's solution is even shorter and more concise.

deleted 822 characters in body
Source Link
Nihathrael
  • 641
  • 4
  • 12
Loading
Add example of fix
Source Link
Nihathrael
  • 641
  • 4
  • 12
Loading
added 178 characters in body
Source Link
Nihathrael
  • 641
  • 4
  • 12
Loading
Source Link
Nihathrael
  • 641
  • 4
  • 12
Loading