python import_module导入方法

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @Time     :2020/3/16 16:44
# @Author    : victor

import importlib
import types


def is_function(tup):
	""" Takes (name, object) tuple, returns True if it is a function.
	"""
	name, item = tup
	return isinstance(item, types.FunctionType)


def import_module(module_list):
	for module in module_list:
		imported = importlib.import_module(module)
		imported_function_list = dict(filter(is_function, vars(imported).items()))
		print(imported_function_list)


if __name__ == '__main__':
	import_module(["utils.logger.mylogger", "utils.parser"])

 

你可能感兴趣的:(python)