您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python的装饰器功能实例

5b51 2022/1/14 8:15:02 python 字数 1009 阅读 296 来源 www.jb51.cc/python

Python的装饰器功能实例

概述


# 来自jb51.cc
@deco1(deco_arg)
@deco2
def func(): pass

# 来自jb51.cc
func = deco1(deco_arg)(deco2(func))

# 来自jb51.cc
# -*-coding:utf-8 -*-
def decorator(str):
  print str
  def retfn(fn):
    def retfn(*arg):
      print '已装饰' # 装饰
      return fn(*arg) # 调用原始函数
    return retfn
  return retfn
 
@decorator("实例化装饰器")
def test(str0,str1):
  print str0,str1
 
test('Hello','world');

总结

以上是编程之家为你收集整理的Python的装饰器功能实例全部内容,希望文章能够帮你解决Python的装饰器功能实例所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶