I am working with code with 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?
You can use this code at the top of the main.py:
Did you look at the suppress warnings section of the python docs?
I don't condone it, but you could just surpress all warnings with this:
Ex:
This is an old question but there is some newer guidance in PEP 565 that to turn off all warnings if you're writing a python application you should use:
The reason this is recommended is that it turns off all warnings by default but crucially allows them to be switched back on via
python -W
on the command line orPYTHONWARNINGS
.You can also define an environment variable (new feature in 2010 - i.e. python 2.7)
Test like this: Default
Ignore warnings
if don't want to complicate then import warnings warnings.filterwarnings("ignore", category=FutureWarning)
There's the -W option.
python -W ignore foo.py