# from account import account
#
# #输入url地址规范是 xxx/xxx
# data = raw_input("请输入地址:")
# if data == 'account/login':
# account.login()
# elif data == 'account/logout':
# account.logout()
#如果使用反射
data = raw_input("请输入地址:")
array = data.split("/")
userspace = __import__('account.'+array[0]) #相当于import account.account
module = getattr(userspace, array[0]) #相当于添加模块,如果没有这一步报(AttributeError: 'module' object has no attribute 'login')
func = getattr(module, array[1]) #相当于account.account.login
func()
python基础---反射应用二
最新推荐文章于 2024-09-19 13:43:29 发布