标签:alt port type post module tom pre www. python
import os
import sys
import importlib # 下文的 v 为字符串类型无法导入,需借助importlib模块
import requests
BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASEDIR) #将根目录auto_client添加到环境变量
from conf import settings
server_info = {}
for k,v in settings.PLUGIN_ITEMS.items():
print(k,v,type(v))
module_path,cls_name =v.rsplit(".",maxsplit=1) #从右侧的.分割v
module = importlib.import_module(module_path)
cls = getattr(module,cls_name) #通过字符串cls_name取到cls
obj = cls()
ret = obj.process() #执行类下process的函数
server_info[k]= ret
requests.post(
url=settings.API,
data = server_info,
)
标签:alt port type post module tom pre www. python
原文地址:http://www.cnblogs.com/hsddon/p/7591908.html