首页 > 其他 > 详细

2016/09/16

时间:2016-09-16 22:41:28      阅读:184      评论:0      收藏:0      [点我收藏+]

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))

  

2016/09/16

原文:http://www.cnblogs.com/wnzhong/p/5877415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!