如何在Python中声明一个模块已弃用?
我希望在导入特定模块或调用其任何函数时打印警告。
warn
函数并搭配一个DeprecationWarning
来发出警告。
具体如何调用并不是很重要,但标准库中有一种针对弃用模块的标准模式,就像这样:
# doc string, top-level comments, imports, __all__ =
import warnings
warnings.warn("the spam module is deprecated", DeprecationWarning,
stacklevel=2)
# normal module code
请参考2.7版本的sets
源代码中的示例。
__init__
中添加print "Deprecated"
或添加一个执行相同操作的装饰器。 - ForceBru__init__
方法在哪里可以找到? - abarnert