> I was expecting the following to catch the DeprecationWarning > > import warnings > > warnings.filterwarnings('error',category=DeprecationWarning) > try: > print (exp(x)*exp(3*x)).simplify_exp() #example with exp function > except DeprecationWarning: > print 'MegBook.py say: exercise needs review!' > > but it does not. I still got > > In Python the warning construct behaves a little differently. I think if you use the "catch_warnings" context manager you'll be able at least test if a warning occurred. See https://docs.python.org/2/library/warnings.html#testing-warnings for information.
import warnings with warnings.catch_warnings(record=True) as w: # # do some things here that may cause a warning # if len(w) > 0: print 'A warning was thrown' -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.