python-反射案例讲解

login.py
#!/usr/bin/dev python
# coding:utf-8


def index():
print u'欢迎访问xx网站首页'

def login():
print u'登录成功'

def logout():
print u'退出登录'

class Person(object):#新式类
def __init__(self):
pass
def info(self):
print u'我是Person类的info的方法'



url = raw_input(u'请输入路由地址:\n')
target_models,target_function = url.split('/')
m =__import__(target_models)
if hasattr(m,target_function):
target_function = getattr(m,target_function)
target_function()
else:
print 'Not Found 404 Page'





login/login
login/logout
 

猜你喜欢

转载自www.cnblogs.com/hyzhang/p/10728774.html
0条评论
添加一条新回复