2018/05/23

Python内置的@property装饰器

[@property](https://www.programiz.com/python-programming/property)

[Decorator](https://wiki.python.org/moin/PythonDecorators#What_is_a_Decorator)

[PythonDecoratorLibrary](https://wiki.python.org/moin/PythonDecoratorLibrary)

[FooFish-Python之禅 :理解 Python 装饰器看这一篇就够了](https://foofish.net/python-decorator.html)

[python @property的用法及含义](https://blog.csdn.net/qq_41673534/article/details/79221070)

#No.1
import logging def use_logging(func): def wrapper():
logging.warn("%s is running" % func.__name__)
return func()
return wrapper def foo():
print('i am foo') foo = use_logging(foo) foo()
import logging

def use_logging(func):

    def wrapper():
logging.warn("%s is running" % func.__name__)
return func()
return wrapper use_logging
def foo():
print("i am foo") foo()
resut:
WARNING:root:foo is running
i am foo
#No.2
import logging def use_logging(level):
def decorator(func):
def wrapper(*args, **kwargs):
if level == "warn":
logging.warn("%s is running" % func.__name__)
elif level == "info":
logging.info("%s is running" % func.__name__)
return func(*args)
return wrapper
return decorator @use_logging(level="warn")
def foo(name='foo'):
print("i am %s" % name) foo()
resut:
WARNING:root:foo is running
i am foo
#No.3
class Rectangle(object):
def __init__(self):
self.width = 10
self.heigh = 20
r = Rectangle()
print(r.width, r.heigh) r.width = 1.0
print(r.width, r.heigh)
resut:
10 20
1.0 20
#No.4
class Rectangle(object):
@property
def width(self):
return self.true_width @property
def height(self):
return self.true_height s = Rectangle()
s.width = 1024
s.height = 768
print(s.width, s.height)
resut:
Traceback (most recent call last):
File "D:/fly/Python/test.py", line 23, in <module>
s.width = 1024
AttributeError: can't set attribute

【坚持】Selenium+Python学习之从读懂代码开始 DAY6的更多相关文章

  1. 【坚持】Selenium+Python学习之从读懂代码开始 DAY1

    学习Selenium+Python已经好几个月了,但越学发现不懂的东西越多. 感觉最大的问题还是在于基础不扎实,决定从头开始,每天坚持读代码,写代码. 相信量变一定能到质变!!! 2018/05/09 ...

  2. 【坚持】Selenium+Python学习之从读懂代码开始 DAY7

    2018/05/25 EC [EC](https://github.com/easonhan007/webdriver_guide/blob/master/34/expected_conditions ...

  3. 【坚持】Selenium+Python学习之从读懂代码开始 DAY5

    2018/05/22 函数作为返回值 [来源:廖雪峰的官方网站](https://www.liaoxuefeng.com/) #No.1 def lazy_sum(*args): def sum(): ...

  4. 【坚持】Selenium+Python学习之从读懂代码开始 DAY3

    2018/05/15 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) #No.1 list = [1, 2, 3, 4] ...

  5. 【坚持】Selenium+Python学习之从读懂代码开始 DAY2

    2018/05/10 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) #No.1 # 二次方程式 ax**2 + bx + ...

  6. 【坚持】Selenium+Python学习之从读懂代码开始 DAY4

    2018/05/21 [生成器详解:廖雪峰的官方网站](https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d ...

  7. 软件测试自动化…python学习到什么程度?代码好不好学!

    软件测试自动化…python学习到什么程度?代码好不好学! 如下:

  8. Gradle学习系列之三——读懂Gradle语法

    在本系列的上篇文章中,我们讲到了创建Task的多种方法,在本篇文章中,我们将学习如何读懂Gradle. 请通过以下方式下载本系列文章的Github示例代码: git clone https://git ...

  9. selenium+python学习总结

    学习了一个月的selenium+python,终于学有所成,下面以一个简单的项目来总结学习所得. 1.         项目结构 在项目结构中,大家要注意到:每一个源文件夹中都要有一个__init__ ...

随机推荐

  1. C++编译器符号表有哪些内容?

    http://blog.csdn.net/wangbingcsu/article/details/48340479 C++编译器符号表有哪些内容? 很早就想写一篇关于符号表的学习小结,可是迟迟不能下笔 ...

  2. css3动画效果小结

    css3的动画功能有以下三种: 1.transition(过度属性) 2.animation(动画属性) 3.transform(2D/3D转换属性) 下面逐一进行介绍我的理解: 1.transiti ...

  3. 用NDK生成so给第三方用

    参考了https://blog.csdn.net/zi413293813/article/details/50074239 然后自己重新整理补充 我用的ndk-r10d ndk下载地址http://d ...

  4. Centos7 yum安装Mysql5.7

    1.下载mysql安装源 curl -LO http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 2.安装yum源 ...

  5. iOS 倒计时的一种实现

    1.view [self performSelectorInBackground:@selector(thread) withObject:nil]; - (void)thread { ;i>= ...

  6. iOS 11 使用方法替换(Method Swizzling),去掉导航栏返回按钮的文字

    方法一:设置BarButtonItem的文本样式为透明颜色,代码如下: [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegro ...

  7. 飞控入门之C语言指针回顾

    指针 何为指针?来个官方定义:指针是一个值为内存地址的变量(或数据对象). 一.指针的声明 //示例 int *pi; //pi是指向int类型变量的指针 char *pc; // pi是指向char ...

  8. 搜集到的一些python资料

    1,MOOC课程-Python语言程序设计(嵩天)http://www.icourse163.org/course/BIT-268001 2,Python123网站(嵩天老师的教学网站):https: ...

  9. WebLogic远程命令执行

    靶机说明 目标ip:172.16.53.28(window 2003) 本靶机所针对的序列化漏洞系列以及常见安全问题如下: 弱口令登陆控制台部署war包webshell CVE-2018-2893 C ...

  10. 关于Matlab在绘图时中文字体显示不一致的问题

    我的运行环境: OS: Win10 教育版 64-bit Matlab版本:Matlab 2017a  64-bit 在使用Matlab绘图时,而横坐标轴.纵坐标轴.标题有汉字时,会发现在GUI的显示 ...