首页 > 编程语言 >python wraps装饰器

python wraps装饰器

时间:2022-08-21 11:00:32浏览次数:54  
标签:__ wraps python doc wrapper print test 装饰

from functools import wraps


def decorator(func):
    """this is decorator __doc__"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        """this is wrapper __doc__"""
        print("this is wrapper method")
        return func(*args, **kwargs)
    return wrapper

@decorator
def test():
    """this is test __doc__"""
    print("this is test method")

print("__name__: ", test.__name__)
print("__doc__:  ", test.__doc__)

标签:__,wraps,python,doc,wrapper,print,test,装饰
From: https://www.cnblogs.com/Higgerw/p/16609627.html

相关文章

  • python输入和类型转换
    输入获取用户使用键盘录入的内容使用的函数是input()变量=input(‘提示的信息’)1.代码从上到下执行,遇到input函数之后 类型转换根据代码的需要,将一种数据类型......
  • 设计模式09 - 设计模式 - 装饰器模式(结构型)
    一、定义装饰器(Decorator)模式:指不改变现有对象结构的情况下,动态地给该对象增加额外功能。它是继承方式的一种替代方案。这种模式创建了一个装饰类,用来包装原有......
  • Notepad plus 通过NppExec插件编译/运行 golang,php,python等语言
        1. 在Notepadplus的插件-->插件管理中,添加nppExec插件。          2.打开插件-->NppExec,选择Showconsole,和Follow($CURRE......
  • python---re
    python---repython的re模块简单使用re.findall,re.compile,re.match和re.searchre.findall这个是最好用的,查找所有符合条件的,返回list,或Noneimportrestr1='gdf......
  • python---struct
    python---structkeywords:structbytespython数据互转https://docs.python.org/3/library/struct.html二进制数据和各种类型数据的转换因为不同平台默认大小端不同,......
  • Python custom modify the __add__ method All In One
    PythoncustommodifytheaddmethodAllInOnePython改写__add__类方法"""#classJuice:#def__init__(self,name,capacity):#self.na......
  • SSD1306 屏幕使用-Micropython
    1、I2C总线是什么?I2C:俗称集成电路总线,是一种简单、双向二线制同步串行通信总线,使用多主从架构。它只需要两根线即可在连接于总线上的器件之间传送信息。主器件用于启动总......
  • 我的python基础知识点
    0、使用#注释,因为python是脚本语言批量赋值a,b=1,2 //a=1,b=2批量赋值还可以使用序列进行赋值a,b=[1,2] //a=1,b=21、在python中,"helloworld"*3//表示3个这个字符......
  • python通过下标替换字符串,指定位置添加字符串
    指定下标替换字符串defreplace_char(old_string,char,index):'''字符串按索引位置替换字符'''old_string=str(old_string)#新的字符串=......
  • Python pandas merge(join) 通过单列或多列合并连接两个DataFrame
    Pythonpandas中处理两个DataFrame时,有些情况我们可能需要将两个DataFrame合并成一个DataFrame,本文主要介绍Pythonpandas中通过单列或多列合并连接两个DataFrame的方法,以......