码迷,mamicode.com
首页 > 编程语言 > 详细

第二模块的python学习第一天记录

时间:2017-08-05 20:29:43      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:generator   str   事务   check   hello   对象   coding   welcome   测试   

 

一、关于装饰器

      #权限校验、用户认证、日志记录、性能测试、事务处理、缓存等都是装饰器的绝佳应用场景

技术分享
 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 
 4 __author__ = andylin
 5 __date__ = 17-8-1 下午9:49
 6 
 7 
 8 
 9 import time
10 
11 
12 def timer(func):
13     def deco(*args,**kwargs):
14         start_time = time.time()
15         func(*args,**kwargs)
16         stop_time = time.time()
17         print("the func run time is %s" % (stop_time - start_time))
18     return deco
19 
20 
21 @timer
22 def test1():
23     time.sleep(1)
24     print("in the test1")
25 
26 test1()
简单的

   

     关于转入的参数

     

技术分享
 1 #!/usr/bin/env python
 2 #-*- coding:utf-8 -*-
 3 
 4 __author__ = andylin
 5 __date__ = 17-8-1 下午9:57
 6 
 7 
 8 uname = "andylin"
 9 passwd = "abc123"
10 
11 def auth(auto_type):
12     def login_check(func):
13         def login(*args,**kwargs):
14             username = input("Username:").strip()
15             password = input("Password:").strip()
16             if username == uname and passwd == password:
17                 if auto_type == job:
18                     func(*args,**kwargs)
19                     print("Authentication Success! Welcome to job!")
20                 elif auto_type == home:
21                     func(*args,**kwargs)
22                     print(Authentication Success!Welcome to home!)
23                 else:
24                     func(*args, **kwargs)
25                     print(Authentication Success!Welcome to shcool!)
26             else:
27                 print("Authentication Faild!")
28         return login
29     return  login_check
30 
31 
32 @auth(auto_type=job)
33 def job():
34     print("login Welcome to job!")
35 
36 @auth(auto_type=home)
37 def home():
38     print("login Welcome to home!")
39 
40 @auth(auto_type=school)
41 def school():
42     print("login Welcome to school!")
43 
44 
45 
46 job()
47 home()
48 school()
输入参数式的

 

二、关于了解Python的数据结构

       容器(container)、可迭代对象(iterable)、迭代器(iterator)、生成器(generator)、列表/集合/字典推导式(list、set  、dict comprehension)众多概念

       可以学习一下这个https://ask.hellobi.com/blog/pythoneer/7688  让我理解了很多

      技术分享

 

第二模块的python学习第一天记录

标签:generator   str   事务   check   hello   对象   coding   welcome   测试   

原文地址:http://www.cnblogs.com/andylinpy/p/7291238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!