#自动引用方法
import commons
inp = input("URL:")
m,f = inp.split(‘/‘)
obj = __import__(m)
def main():
if hasattr(obj,f):
func = getattr(obj,f)
func()
else:
print(‘404‘)
main()
下面是commons
def login():
print("login")
def logout():
print("logout")
def home():
print("home")
输出结果:
URL:commons/home
home
原文地址:http://liulidong.blog.51cto.com/9439411/1790472