I was setting up a ImportWarning as seemed appropriate but noticed this warning is not reported by default;
我当时正在建立一个看似合适但却注意到这个警告并没有被默认报告的情况;
How can I set python to report ImportWarning or all warnings?
如何让python报告ImportWarning或所有警告?
Here is the import warning i wrote:
这里是我写的进口警告:
try:
from markdown import markdown
except ImportError, err:
warnings.warn(
'Unable to load Pypi package `markdown`, HTML output will be unavailable. {}'.format(err),
ImportWarning
)
2 个解决方案
#1
5
import warnings
warnings.simplefilter('module')
Or:
或者:
import warnings
warnings.simplefilter('always')
The list of filters are in the docs
过滤器列表在文档中
#2
8
To enable warnings run python with the -Wdefault
or -Wd
switch.
要启用wd警告,请使用-Wdefault或-Wd开关运行python。
#1
5
import warnings
warnings.simplefilter('module')
Or:
或者:
import warnings
warnings.simplefilter('always')
The list of filters are in the docs
过滤器列表在文档中
#2
8
To enable warnings run python with the -Wdefault
or -Wd
switch.
要启用wd警告,请使用-Wdefault或-Wd开关运行python。