问题
Assuming I write a python package that has to use the imp
module, and my package is "TestModule" which is the following:
import imp
import pip
import sys
def update_and_reload(module, *args, **kwargs):
pip.main(['install', module, '--upgrade', '--user'])
return imp.reload(module)
When I do import TestModule
in the terminal, I get a pending deprecation warning on imp
. How would I make imp
's warning not occur / filter out?
回答1:
Well you could use the warning module:
import warnings
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
import imp
import pip
...
来源:https://stackoverflow.com/questions/32277931/suppress-warnings-on-import