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

做国外的营销的网站站长统计代码

做国外的营销的网站,站长统计代码,新疆石油工程建设监理有限责任公司网站,海南政府网站集约化建设Register用法 1. 为什么使用Register2. 先验知识-----装饰器2.1 代码视角的装饰器用法2.2 装饰器的使用场景2 3. Registry注册器参数parent介绍未完待续 1. 为什么使用Register 2. 先验知识-----装饰器 2.1 代码视角的装饰器用法 实例1 decorate def func():pass #! 等价于…

Register用法

  • 1. 为什么使用Register
  • 2. 先验知识-----装饰器
    • 2.1 代码视角的装饰器用法
    • 2.2 装饰器的使用场景2
  • 3. Registry注册器参数parent介绍
  • 未完待续

1. 为什么使用Register

2. 先验知识-----装饰器

2.1 代码视角的装饰器用法

  • 实例1
@decorate
def func():pass
#! 等价于func = decorate(func)
  • 实例2
def a_new_decorator(a_func):def wrapTheFunction():print("I am doing some boring work before executing a_func()")a_func()print("I am doing some boring work after executing a_func()")return wrapTheFunction@a_new_decorator
def a_function_requiring_decoration():"""Hey yo! Decorate me!"""print("I am the function which needs some decoration to remove my foul smell")a_function_requiring_decoration()
# Output: I am doing some boring work before executing a_func()
#         I am the function which needs some decoration to remove my foul smell
#         I am doing some boring work after executing a_func()print(a_function_requiring_decoration.__name__)
# Output: wrapTheFunction

实际上我们希望"name"函数输出函数的名字,这样在后续代码排查的时候可以提高效率,但是这里的函数被wrapTheFunction代替了,重写了我们的函数名字和注释文档。因此在python需要借用functools.warps来解决这个问题。

  • 实例3
def a_new_decorator(a_func):@wrap(a_func)def wrapTheFunction():print("I am doing some boring work before executing a_func()")a_func()print("I am doing some boring work after executing a_func()")return wrapTheFunction@a_new_decorator
def a_function_requiring_decoration():"""Hey yo! Decorate me!"""print("I am the function which needs some decoration to remove my foul smell")a_function_requiring_decoration()
# Output: I am doing some boring work before executing a_func()
#         I am the function which needs some decoration to remove my foul smell
#         I am doing some boring work after executing a_func()print(a_function_requiring_decoration.__name__)
# Output:a_function_requiring_decoratio

2.2 装饰器的使用场景2

  • 实例1(带参数的装饰器)
from functools import wrapsdef logit(logfile='out.log'):def logging_decorator(func):@wraps(func)def wrapped_function(*args, **kwargs):log_string = func.__name__ + " was called"print(log_string)# 打开logfile,并写入内容with open(logfile, 'a') as opened_file:# 现在将日志打到指定的logfileopened_file.write(log_string + '\n')return func(*args, **kwargs)return wrapped_functionreturn logging_decorator@logit()
def myfunc1():passmyfunc1()
# Output: myfunc1 was called
# 现在一个叫做 out.log 的文件出现了,里面的内容就是上面的字符串@logit(logfile='func2.log')
def myfunc2():passmyfunc2()
# Output: myfunc2 was called
# 现在一个叫做 func2.log 的文件出现了,里面的内容就是上面的字符串

3. Registry注册器参数parent介绍

在 Python 的 “Registry”(注册器)模式中,参数 “parent” 通常表示父级对象或父级注册器。“Registry” 模式用于管理、存储和检索对象、函数或其他实体,允许不同的组件或模块向注册器中注册或注销实体,然后其他组件可以查询并使用这些实体。

当在 “Registry” 模式中使用参数 “parent” 时,通常是指在注册一个实体时,需要将其关联到某个父级对象或父级注册器。这可以用于创建层次结构、管理依赖关系或组织数据。

下面是一个示例,展示了在 “Registry” 模式中使用参数 “parent” 的可能含义:

class Registry:def __init__(self):self._registry = {}def register(self, name, item, parent=None):if parent is not None:parent.register(name, item)else:self._registry[name] = item# 使用示例
root_registry = Registry()
child_registry = Registry()root_registry.register("item_a", "Item A")
child_registry.register("item_b", "Item B", parent=root_registry)

在这个示例中,我们定义了一个 “Registry” 类,其中的 register 方法接受参数 “parent”。当注册实体时,如果指定了 “parent” 参数,那么实体将被注册到父级注册器中,否则将被注册到当前注册器中。这允许我们创建层次结构的注册器,其中子注册器可以继承父注册器中的实体。

需要注意的是,具体的含义和用法可能会根据你的需求和实现方式而有所不同。在 “Registry” 模式中,参数 “parent” 的含义取决于你如何设计和使用注册器。

未完待续

注册 构建

http://www.hkea.cn/news/706525/

相关文章:

  • wordpress的数据库在那里百度seo如何快速排名
  • wordpress手机客服代码免费seo快速排名工具
  • web网站开发作品关键词歌词图片
  • 汕头行业网站seo培训公司
  • 网站背景图片优化关键词歌曲免费听
  • 郑州做网站哪家专业我要发布信息
  • 西安做网站优化的公司石家庄seo按天扣费
  • 2022年西安封城通知自动app优化下载
  • 无锡做网站哪家公司好一个公司可以做几个百度推广
  • 专题网站建设工作关键词林俊杰无损下载
  • adobe 网站开发软件软文写作兼职
  • 英文网站建设 淮安免费培训网站
  • 隔离需要多少钱湖南网站seo找行者seo
  • wordpress简单企业站seo怎么刷排名
  • 网站建设与运维泉州全网推广
  • 网站建站哪个公司好一点营销咨询服务
  • 值得玩的网页游戏北京seo营销培训
  • 中国建设银行网站分期通百度推广登录平台网址
  • 公司内部网站源码新闻软文推广案例
  • vf建设银行网站谷歌seo排名
  • 如何申请商业服务器武汉seo工厂
  • 祥云平台英文网站微博指数查询入口
  • 公司网站建设准备资料今日重大财经新闻
  • 发布网站后备案免费网站建站页面
  • 浙江建设职业技术学院迎新网站做一个网站要多少钱
  • axure做网站好不好手机百度问一问
  • 开发微信小程序的流程广州seo优化电话
  • 小企业网站建设和管理全能搜
  • 无棣县建设局网站游戏优化大师下载安装
  • 小额贷款 网站模板品牌推广软文