相关疑难解决方法(0)

如何制作一系列功能装饰器?

如何在Python中创建两个装饰器来执行以下操作?

@makebold
@makeitalic
def say():
   return "Hello"
Run Code Online (Sandbox Code Playgroud)

...应该返回:

"<b><i>Hello</i></b>"
Run Code Online (Sandbox Code Playgroud)

我不是试图HTML在一个真实的应用程序中这样做 - 只是试图了解装饰器和装饰器链是如何工作的.

python decorator python-decorators

2647
推荐指数
17
解决办法
49万
查看次数

如何在Python中禁用和重新启用控制台日志记录?

我正在使用Python的日志记录模块,我想暂时禁用控制台日志记录,但它不起作用.

#!/usr/bin/python
import logging

logger = logging.getLogger() # this gets the root logger
# ... here I add my own handlers 
#logger.removeHandler(sys.stdout)
#logger.removeHandler(sys.stderr)

print logger.handlers 
# this will print [<logging.StreamHandler instance at ...>]
# but I may have other handlers there that I want to keep

logger.debug("bla bla")
Run Code Online (Sandbox Code Playgroud)

上面的代码显示了bla blaon stdout,我不知道如何安全地禁用控制台处理程序.我怎么能确定我暂时删除了控制台StreamHandler而不是另一个?

python console logging stdout

134
推荐指数
9
解决办法
14万
查看次数

标签 统计

python ×2

console ×1

decorator ×1

logging ×1

python-decorators ×1

stdout ×1