首页 > 代码库 > 2016/09/16
2016/09/16
1. Python视频
B. 装饰器
装饰器实例:用户管理程序
LOGIN_USER = {‘is_login‘: False}def outer(func): def inner(*args, **kwargs): if LOGIN_USER[‘is_login‘]: r = func() return r else: print(‘please login‘) return inner@outerdef order(): print(‘welcome %s‘%LOGIN_USER[‘current_user‘])@outerdef change_pwd(): print(‘welcome %s‘%LOGIN_USER[‘current_user‘])@outerdef manager(): print(‘welcome %s‘%LOGIN_USER[‘current_user‘])def login(user, pwd): if user == ‘alex‘ and pwd == ‘123‘: LOGIN_USER[‘is_login‘] = True LOGIN_USER[‘current_user‘] = user print(‘welcome %s‘ % LOGIN_USER[‘current_user‘])def main(): while True: inp = input(‘1.login 2.manager 3.change pwd 4.order‘) if inp == ‘1‘: username = input(‘input username‘) pwd = input(‘input password‘) login(username, pwd) elif inp == ‘2‘: manager() elif inp == ‘3‘: change_pwd() elif inp == ‘4‘: order()main()
2. time module
import timestart = time.clock()......end = time.clock()print( ‘program processing time: %f‘%(end - start))
2016/09/16
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。