Skip to content

Instantly share code, notes, and snippets.

@SuoXC
Last active March 11, 2019 09:13
Show Gist options
  • Save SuoXC/83550148a41778f4d032033496ec0b6d to your computer and use it in GitHub Desktop.
Save SuoXC/83550148a41778f4d032033496ec0b6d to your computer and use it in GitHub Desktop.
auto register sub modules in current dir
import os
import importlib
# 自动注册当前文件夹下所有模块
module_dir = os.path.dirname(__file__)
for i in os.listdir(module_dir):
module_name = os.path.basename(i).split('.')[0]
importlib.import_module('.' + module_name, __package__)
# usage:
# import a
# a.b.xxxx()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment