2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -6,20 +6,20 @@
In [1]:
```
```py
import warnings
```
在需要的地方,我们使用 `warnings` 中的 `warn` 函数:
```
```py
warn(msg, WarningType = UserWarning)
```
In [2]:
```
```py
def month_warning(m):
if not 1<= m <= 12:
msg = "month (%d) is not between 1 and 12" % m
@@ -29,14 +29,14 @@ month_warning(13)
```
```
```py
c:\Anaconda\lib\site-packages\IPython\kernel\__main__.py:4: RuntimeWarning: month (13) is not between 1 and 12
```
有时候我们想要忽略特定类型的警告,可以使用 `warnings``filterwarnings` 函数:
```
```py
filterwarnings(action, category)
```
@@ -44,7 +44,7 @@ filterwarnings(action, category)
In [3]:
```
```py
warnings.filterwarnings(action = 'ignore', category = RuntimeWarning)
month_warning(13)