Created
July 14, 2017 12:55
-
-
Save tag1216/8dc6824739d627e66094c3e232acac70 to your computer and use it in GitHub Desktop.
ディレクトリ内のPythonファイルを動的インポート
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from glob import glob | |
from importlib import import_module | |
sys.path.append('plugins') | |
for path in glob('plugins/*.py'): | |
filename = os.path.basename(path) | |
print(filename) | |
module_name = os.path.splitext(filename)[0] | |
import_module(module_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment