zoukankan      html  css  js  c++  java
  • 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
    
    
    @outer
    def order():
    		print('welcome %s'%LOGIN_USER['current_user'])
    
    
    @outer
    def change_pwd():
    		print('welcome %s'%LOGIN_USER['current_user'])
    
    
    @outer
    def 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 time
    start = time.clock()
    ...
    ...
    end = time.clock()
    print( 'program processing time: %f'%(end - start))
    

      

  • 相关阅读:
    申请加分项
    课程评价
    本周总结
    热词2
    热词1
    php大作业
    css网格布局
    php实验4
    本周总结
    css边框图像
  • 原文地址:https://www.cnblogs.com/wnzhong/p/5877415.html
Copyright © 2011-2022 走看看