如何消除python中的VisibleDeprecationWarning DeprecationWarning等类似警告:

转自:https://blog.csdn.net/weixin_41884148/article/details/88783554

如何消除python中的VisibleDeprecationWarning DeprecationWarning等类似警告:

我们在写相关代码时总会有一些警告,虽然并不影响结果,但是很影响美观。如果在不急于解决警告的情况下我们可以选择一些方法进行忽略。
eg:

VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0;

DeprecationWarning: This function is deprecated. Please call randint(0, 1 + 1) instead;

添加代码如下:

import warnings
warnings.filterwarnings("ignore", category=Warning)

原文链接:https://blog.csdn.net/weixin_41884148/article/details/88783554

原文地址:https://www.cnblogs.com/chuqianyu/p/15024021.html