Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
Functools.update_wrapper() 无法正常工作
I use Functools update wrapper 在我的装饰器中 但看起来像update wrapper仅重写函数属性 例如 doc name 但不影响help 功能 我知道这些答案 https stackoverflow co
python
python27
decorator
pythondecorators
functools
如何从初始化参数中正确设置 Python 类属性
作为一名 Python 程序员 我经常声明类似的类 class Foo def init self attr1 attr2 attr3 attr4 attr5 attr6 attr7 attr8 attr9 self attr1 attr1
python
pythondecorators
readability
如何使用 python-decorator 包来装饰类方法?
我有一个装饰器 我想用它来装饰类方法 在下面的示例中 mydec 装饰器本身可以正常工作 但是在使用 help 或 pydoc 时它不会保留函数签名 为了解决这个问题 我研究了使用 decorator python decorator 包
python
decorator
classmethod
pythondecorators
使用装饰器将类方法包装在 try / except 中
我有一个通用函数 可以将有关异常的信息发送到应用程序日志 我用exception handler来自类中方法的函数 传入并由应用程序调用的应用程序日志处理程序exception handler创建一个 JSON 字符串 该字符串是实际发送到
python
python27
decorator
pythondecorators
返回响应后如何记录 POST 方法的返回值?
我正在开发我的第一个 REST API 所以如果我错过了一些基本的东西 请提前道歉 我有一个函数 它从另一台服务器获取 JSON 请求 对其进行处理 根据数据进行预测 然后返回另一个带有结果的 JSON 我想在服务器的本地磁盘上保留对此端点
python3x
logging
FastAPI
pythondecorators
python setattr 用于带有装饰器的动态方法创建器
我有一个定义了多个方法的类 import mat class Klass object mat sell mat CanSet def method1 self return None mat sell mat CanSet def met
python
decorator
factory
pythondecorators
setattr
python装饰器,嵌套函数[重复]
这个问题在这里已经有答案了 我试图弄清楚为什么在使用装饰器时我需要一个嵌套函数 这是一个例子 def func f def deco args kwargs return f args kwargs return deco func def
python
pythondecorators
Django - 将参数传递给 CBV 装饰器的正确方法?
文档功能应用装饰器的不错选择 例如login required基于类的视图 https docs djangoproject com en dev topics class based views intro decorating the
Flask:为什么 app.route() 装饰器应该总是在最外面?
说吧 我有一个手工制作的 login required装饰器 from functools import wraps def login required decorated function Decorator to check if u
python
Flask
decorator
pythondecorators
getter 和 setter 的 Google 样式指南属性
我对其中的一项建议感到好奇有关属性的 Google Python 风格指南 https google github io styleguide pyguide html Properties 他们在其中给出了以下示例 class Squar
python
properties
decorator
pythondecorators
googlestyleguide
在 Python 3 中创建抽象属性会导致 AttributeError
如何在 python 中创建抽象属性 import abc class MyClass abc ABC abc abstractmethod property def foo self pass 结果出现错误AttributeError a
python
python3x
abstract
pythondecorators
检查函数是否被修饰
我正在尝试在类方法中构建一个控制结构 该方法将函数作为输入 并且如果函数被修饰或未修饰 则具有不同的行为 关于如何构建函数的任何想法is decorated其行为如下 def dec fun do decoration def func d
python
python3x
closures
decorator
pythondecorators
无法在装饰器中捕获 pytest 的结果
我的 pytest 测试装饰器在调用函数后立即退出装饰器 如果我使用 python 而不是 pytest 运行该文件 效果会很好 这是代码 def dec func def wrapper args kwargs print do some
python
Pytest
pythondecorators
如何使用装饰器计算函数调用次数?
我正在刷新我对一些我还没有得到的Python功能的记忆 我正在从中学习这个Python教程 http www python course eu python3 decorators php还有一个我不完全理解的例子 这是关于装饰器计算对函数
python
pythondecorators
Python 从装饰器导入模块
我正在使用 Python 3 开发一个应用程序 而且我所做的事情是非常规的 cx Oracle 是一个很难设置的模块 对于我的应用程序来说是一个可选的依赖项 我想做的是将模块的导入包装在装饰器中 仅放置在使用它的函数之上 这将避免必须在我的
python
python3x
pythonimport
pythondecorators
为 click.options() 创建包装装饰器
我正在尝试为点击装饰器创建一个包装装饰器 click options foo required True import click def foo option func orig decorator click option foo re
python
pythondecorators
pythonclick
AttributeError:“WSGIRequest”对象在 OAuth2Decorator 上没有属性“request”
我在 Google App Engine 上使用 Django 尝试访问 Google API 时遇到了问题 我想使用装饰器 如文档中所述 但我一遍又一遍地遇到相同的错误 AttributeError WSGIRequest object
如何在 Sphinx 文档中将成员注释为抽象?
以下两个属性定义在 Sphinx 中显示完全相同autodocHTML 输出 property def concrete self This is the concrete docstring pass abstractproperty d
python
pythonsphinx
pythondecorators
autodoc
ABC
有人可以解释一下 staticmethod 的源代码在 python 中是如何工作的吗
首先 我了解装饰器一般是如何工作的 而且我知道 staticmethod去掉签名中的实例参数 使得 class C object staticmethod def foo print foo C foo
python
decorator
staticmethods
pythondecorators
pythoninternals
python Flask如何将动态参数传递给装饰器
我正在使用 python Flask 框架 我写了一个装饰器 它需要一个参数 并且这个参数将是动态的 我的装饰器如下所示 将获得一个密钥 并使用该密钥从 Redis 获取数据 def redis hash shop style key de
python
Flask
Redis
pythondecorators
1
2
3
»