[AstroPy] Capturing pyfits warnings
jtaylor2 at stsci.edu
jtaylor2 at stsci.edu
Tue Sep 14 15:00:23 EDT 2010
Tom,
Jim's suggestion should work as long as what is being generated is an exception and not a warning. If a warning is being generated through the warnings module, you will need to have the warning module generate an exception instead of a warning message. The PyFITS user manual gives an example of ignoring a warning message, but the same template applies to raising an exception. Just replace the word 'ignore' in the samples with the word 'error'.
So when starting a python session use:
python -W"error"
Or when running a script:
python -W"error" myscript.py
Or within your script:
import warnings
import pyfits
warnings.resetwarnings()
warnings.filterwarnings('error', category=UserWarning, append=True)
# do your thing.
Then using Jim's try/except block should get these warnings as well.
Jim T.
More information about the AstroPy
mailing list