码迷,mamicode.com
首页 > 其他好文 > 详细

2016/09/16

时间:2016-09-16 22:41:59      阅读:141      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!