当前位置: 首页 > news >正文

国外的响应式网站模板wordpress二开前端

国外的响应式网站模板,wordpress二开前端,高中信息技术课网站怎么做,网站开发有哪几类写在前面:python装饰器(fuctional decorators)就是用于拓展原来函数功能的一种函数#xff0c;目的是在不改变原函数名(或类名)的情况下#xff0c;给函数增加新的功能。 这个函数的特殊之处在于它的返回值也是一个函数#xff0c;这个函数是内嵌“原“”函数的函数。一般而…写在前面:python装饰器(fuctional decorators)就是用于拓展原来函数功能的一种函数目的是在不改变原函数名(或类名)的情况下给函数增加新的功能。 这个函数的特殊之处在于它的返回值也是一个函数这个函数是内嵌“原“”函数的函数。一般而言我们要想拓展原来函数代码最直接的办法就是侵入代码里面修改例如importtimedeff():print(hello)time.sleep(1)print(world)这是我们最原始的的一个函数然后我们试图记录下这个函数执行的总时间那最简单的做法就是改动原来的代码importtimedeff():start_timetime.time()print(hello)time.sleep(1)print(world)end_timetime.time()execution_time (end_time - start_time)*1000print(time is %d ms %execution_time)但是实际工作中有些时候核心代码并不可以直接去改所以在不改动原代码的情况下我们可以再定义一个函数。(但是生效需要再次执行函数)importtimedefdeco(func):start_timetime.time()func()end_timetime.time()execution_time (end_time - start_time)*1000print(time is %d ms %execution_time)deff():print(hello)time.sleep(1)print(world)if __name__ __main__:deco(f)print(f.__name__ is,f.__name__)print()这里我们定义了一个函数deco它的参数是一个函数然后给这个函数嵌入了计时功能。但是想要拓展这一千万个函数功能就是要执行一千万次deco()函数所以这样并不理想接下来我们可以试着用装饰器来实现先看看装饰器最原始的面貌。importtimedefdeco(f):defwrapper():start_timetime.time()f()end_timetime.time()execution_time (end_time - start_time)*1000print(time is %d ms %execution_time )returnwrapperdecodeff():print(hello)time.sleep(1)print(world)if __name__ __main__:f()这里的deco函数就是最原始的装饰器它的参数是一个函数然后返回值也是一个函数。其中作为参数的这个函数f()就在返回函数wrapper()的内部执行。然后在函数f()前面加上decof()函数就相当于被注入了计时功能现在只要调用f()它就已经变身为“新的功能更多”的函数了(不需要重复执行原函数)。扩展1带有固定参数的装饰器importtimedefdeco(f):defwrapper(a,b):start_timetime.time()f(a,b)end_timetime.time()execution_time (end_time - start_time)*1000print(time is %d ms %execution_time)returnwrapperdecodeff(a,b):print(be on)time.sleep(1)print(result is %d %(ab))if __name__ __main__:f(3,4)扩展2无固定参数的装饰器importtimedefdeco(f):def wrapper(*args, **kwargs):start_timetime.time()f(*args, **kwargs)end_timetime.time()execution_time_ (end_time - start_time)*1000print(time is %d ms %execution_time)returnwrapperdecodeff(a,b):print(be on)time.sleep(1)print(result is %d %(ab))decodeff2(a,b,c):print(be on)time.sleep(1)print(result is %d %(abc))if __name__ __main__:f2(3,4,5)f(3,4)扩展3使用多个装饰器装饰一个函数importtimedefdeco01(f):def wrapper(*args, **kwargs):print(this is deco01)start_timetime.time()f(*args, **kwargs)end_timetime.time()execution_time (end_time - start_time)*1000print(time is %d ms %execution_time)print(deco01 end here)returnwrapperdefdeco02(f):def wrapper(*args, **kwargs):print(this is deco02)f(*args, **kwargs)print(deco02 end here)returnwrapperdeco01deco02deff(a,b):print(hello,here is a func for add :)time.sleep(1)print(result is %d %(ab))if __name__ __main__:f(3,4)this is deco01this is deco02hellohere is a func for add :result is 7deco02 end heretime is 1003 msdeco01 end here装饰器调用顺序装饰器是可以叠加使用的那么使用装饰器以后代码是啥顺序呢对于Python中的””语法糖装饰器的调用顺序与使用 语法糖声明的顺序相反。在这个例子中”f(3, 4) deco01(deco02(f(3, 4)))”。
http://www.hn-smt.com/news/3548/

相关文章:

  • 第三十篇
  • Java 集合 “Map(1)”面试清单(含超通俗生活案例与深度理解) - 教程
  • 0295-Nand-时序逻辑
  • Python逻辑运算 _ 今年过节能收礼吗
  • 【SPIE出版、往届已EI检索】第二届遥感技术与图像处理国际学术会议(RSTIP 2025)
  • 2025年叠元宝机器厂家权威推荐榜单:自动元宝机/金银元宝机 /全自动元宝机源头厂家精选
  • RecyclerView使用-涂鸦智能App的首页和添加效果-从0到1过程
  • 微信商户号的对接,不同主体实现 - A公司换B公司银行收款账号
  • C++对象模型和this指针Project5
  • 2025年络合铁脱硫剂厂家爱权威推荐榜单:沼气脱硫剂/天然气脱硫剂 /铁基脱硫剂源头厂家精选
  • 微波雷达和毫米波雷达有什么区别
  • 2025年绞吸式抽沙船厂家权威推荐榜单:绞吸式清淤船/绞吸挖泥船 /绞吸抽沙船源头厂家精选
  • 2025年胶纸封箱机厂家爱权威推荐榜单:两侧驱动封箱机/全自动胶带封箱机 /全自动角边封箱机源头厂家精选
  • 2025年靠谱的汽车改装厂家最新推荐权威榜
  • Notion和Airtable之后,下一个现象级效率神器会是Dify吗?
  • 软考复习 - 2025/10/30
  • 2025 年 10 月预制舱厂家推荐排行榜,光伏预制舱,风电光伏预制舱,储能预制舱,一二次设备电气预制舱,SVG 预制舱,控制预制舱公司推荐
  • 2025年比较好的数字化涂装生产线厂家推荐及选择参考
  • 基于英飞凌MCU实现BLDC无感正弦波FOC控制
  • .NET6 Web程序部署在IIS上
  • HarmonyOS自动化测试与持续集成实战指南
  • 2025年质量好的商用电器开关行业内口碑厂家排行榜
  • 2025年10月珠海酒店推荐榜:十家高分住宿全维度对比
  • 2025年口碑好的粉末冶金齿轮厂家实力及用户口碑排行榜
  • Affinity Photo 2.6.5 (macOS, Windows) - 梦寐以求的照片编辑器
  • Adobe Photoshop 2026 v27.0 (macOS, Windows) - 照片和设计软件
  • 2025年评价高的双功能缓冲滑轨厂家最新权威实力榜
  • Ngene 代码
  • 2025年水平生命线工厂权威推荐榜单:水平生命线系统/钢结构生命线/防坠落水平生命线源头厂家精选
  • 2025.10.28__jyu每日一题题解