2017-10-02 15 views

答えて

0

あなたが例外に警告を強制しますwarnings.simplefilter("error")、例えば使用することができますよりも、例外を発生させるために警告を引き起こす場合:

In []: 
import warnings 
warnings.simplefilter("error") 
try: 
    np.arccos(10) 
except RuntimeWarning: 
    print('error') 

Out[]: 
error 

代替は、あなたがwarnings.catch_warnings(record=True)コンテキストマネージャとの警告を記録することができました:

In []: 
import warnings 

with warnings.catch_warnings(record=True) as ws: 
    np.arccos(10) 
for w in ws: 
    print(w.message) 

Out[]: 
invalid value encountered in arccos 
関連する問題