python简单路由系统
1 # 输入模块名/函数 2 url = input('请输入网址:') 3 module,func = url.split('/') 4 m = __import__('lib.'+module,fromlist=True) 5 if hasattr(m,func): 6 target = getattr(m,func) 7 r = target() 8 print(r) 9 else: 10 print('404')
1 # 输入模块名/函数 2 url = input('请输入网址:') 3 module,func = url.split('/') 4 m = __import__('lib.'+module,fromlist=True) 5 if hasattr(m,func): 6 target = getattr(m,func) 7 r = target() 8 print(r) 9 else: 10 print('404')