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. 关于右键属性与du -sh显示的文件大小不一致的解决

    du -sh filename(其实我们经常用du -sh *,显示当前目录下所有的文件及其大小,如果要排序再在后面加上 | sort -n)   关于右键属性与du -sh显示的文件大小不一致的解决 ...

  2. RabbitMQ 6种应用场景

    http://www.rabbitmq.com/getstarted.html官网 最近业务需要使用Rabbitmq工作队列实现任务的负载分发 1.1.什么是RabbitMQ? RabbitMQ是实现 ...

  3. Linux - Seafile

    0. 摘要 Seafile 是一款开源的企业云盘,注重可靠性和性能.支持 Windows, Mac, Linux, iOS, Android 平台.支持文件同步或者直接挂载到本地访问. AWS(亚马逊 ...

  4. 【转】iOS:AvPlayer设置播放速度不生效的解决办法

    现象: 项目有一个需求是实现视频的慢速播放,使用的是封装的AvPlayer,但是设置时发现比如设置rate为0.5,0.1,0.01都是一样的速度,非常疑惑.后来经过查找资料,发现iOS10对这个AP ...

  5. TensorFlow函数(十)tf.global_variables_initializer()

    tf.global_variables_initializer() 此函数是初始化模型的参数 with tf.Session() as sess: tf.global_variables_initia ...

  6. Jenkins启动和停止服务

    1.怎么启动Jenkins? step1:进入到Jenkins的war包所在的目录. 如果是win7及以上版本,直接打开Jenkins的war包所在的目录,在地址栏敲cmd,回车. 上述结果和进入cm ...

  7. 【js】按下enter键禁止表单自动提交

    //enter键盘事件 document.onkeypress=function(){ if(event.keyCode==13){ return false; } }

  8. linux文件系统初始化过程(5)---加载initrd(下)

    一.目的 linux把文件分为常规文件.目录文件.软链接文件.硬链接文件.特殊文件(设备文件.管道文件.socket文件等)几种类型,分别对应不同的新建函数sys_open().sys_mkdir() ...

  9. iOS开发用如何用类"SKStoreProductViewController"跳转AppStore点赞评分?

    大家都知道,评论和评分是决定app在appstore中排名的重要因素,但是大部分用户下载安装APP后却不会去点评,所以添加提示用户去点评的功能是很必要的. 目前,AppStore点赞评分有两种方法,一 ...

  10. TopJUI | easyui HTML Dialog页面间GET方式数据传递

    较容易的方式通过URL内带参数进行数据传递 var url = "apddList.html?c0=" + row.uuid + "&c1=" + ro ...