Source From Here
Question
I am working with code that throws a lot of (for me at the moment) useless warnings using the warnings library. Reading (/scanning) the documentation I only found a way to disable warnings for single functions. But I don't want to change so much of the code.
Is there maybe a flag like python -no-warning foo.py?
What would you recommend?
How-To
For the command line, there's the -W option.
You can also check the suppress warnings section of the python docs:
For example:
I don't condone it, but you could just suppress all warnings with this:
Ex:
Question
I am working with code that throws a lot of (for me at the moment) useless warnings using the warnings library. Reading (/scanning) the documentation I only found a way to disable warnings for single functions. But I don't want to change so much of the code.
Is there maybe a flag like python -no-warning foo.py?
What would you recommend?
How-To
For the command line, there's the -W option.
You can also check the suppress warnings section of the python docs:
For example:
- import warnings
- def fxn():
- warnings.warn("deprecated", DeprecationWarning)
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- fxn()
- import warnings
- warnings.filterwarnings("ignore")
沒有留言:
張貼留言