因此,我使用的是第三方库中的method_x,每次使用它时都会打印警告。由于我正在编写一些用于从cli获取用户输入的代码,所以我想阻止这些恼人的打印。
import module_x
module_x.method_x() # Has expected behaviour but prints an annoying warning
我能做些什么来阻止函数中的所有打印语句吗?也许用什么东西包装这个方法或者暂时禁用stdout?
编辑:我最后使用了日志模块的一种方法,该方法捕获警告并将它们重定向到日志文件。这是我做的装饰师:
logging.basicConfig(filename='
在一个单元测试中,我最近得到了
werkzeug/local.py:347: DeprecationWarning: json is deprecated. Use get_json() instead.
我将其追溯到相关的文件venv/lib/python3.6/site-packages/werkzeug/local.py。有问题的行是以下方法中的最后一行。
def __getattr__(self, name):
if name == '__members__':
return dir(self._get_current_object())
几乎所有使用npm安装软件包的时候,我都会收到如下警告:
npm WARN deprecated minimatch@1.0.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
然后,我安装带有建议版本号的可疑软件包。
有什么方法可以让npm自动完成这个任务吗?当然要冒着自己的风险。
我有一个Visual c++项目,在这里我使用链接器设置
/WX (TreatWarningsAsLinkerErrors=true)
在调试中,我使用/Zi (调试数据库)进行编译,它运行良好。
现在我有了一个第三方SDK,它附带了一个静态库,但没有.pdb文件。一旦我将这个文件链接到Debug中,我就会得到
LNK4099: 3rd-party.lib(3rd-party.obj) : warning LNK4099: PDB "vc90.pdb" was not found "3rd-party.lib(3rd-party.obj)" or with
我在Eclipse中发现了一些奇怪的东西。假设我有以下课程:
public class Super {
@Deprecated
public void doNotUseThisMethod() {
// do magic
}
}
public class Sub extends Super{
@Override
public void doNotUseThisMethod() {
// why is this not deprecated?
}
}
重写不推荐的方法肯定会导致警告(因为不使用它的原因相同)。不过,
在保存/加载gensim单词嵌入时,我会收到以下弃用警告:
model.save("mymodel.model")
/home/.../lib/python3.7/site-packages/smart_open/smart_open_lib.py:398:
UserWarning: This function is deprecated, use smart_open.open instead.
See the migration notes for details:
'See the migration notes for details: %s'