0

I'm using warnings.warn(), together with a print, but the warnings are not returned:

if[1!=2]:
    print('Error')
    warnings.warn('Warning!')
#returns:  Error

I'm using Jupyter. Would appreciate if someone could assist

Sos
  • 1,364
  • 13
  • 34
  • Are you also looking at your error output? (stderr). `warnings.warn` probably writes there while print writes on stdout – smagnan Oct 24 '19 at 13:59
  • It prints it out in my console. Look here: https://stackoverflow.com/questions/9031783/hide-all-warnings-in-ipython#9031848 maybe there's something in your jupyter startup files – gst Oct 24 '19 at 14:00
  • Works fine for me. Cannot reproduce the issue. See these posts, maybe there is something related to your issue: [Configure IPython to show warnings all the time](https://stackoverflow.com/q/27787677/7851470), [Jupyter notebook does not print logs to the output cell](https://stackoverflow.com/q/35936086/7851470) – Georgy Oct 24 '19 at 14:03
  • Also: https://stackoverflow.com/a/37979724/3465514 and https://stackoverflow.com/a/40667761/3465514: two good comments that explain how warning display is handled, it might have been called already and the following calls are muted – smagnan Oct 24 '19 at 14:06
  • 1
    Thanks a lot guys. This was working fine a bit ago, suddenly it stopped working. @gst : terminal shows nothing there when running this jupyter cell. Thanks to your links, I solved it with `warnings.filterwarnings('always')`. I guess I will need to include it in my preamble. Also, I've voted to close since [https://stackoverflow.com/questions/27787677/configure-ipython-to-show-warnings-all-the-time](this) was the same question (and solution) – Sos Oct 24 '19 at 14:12
  • 1
    Possible duplicate of [Configure IPython to show warnings all the time](https://stackoverflow.com/questions/27787677/configure-ipython-to-show-warnings-all-the-time) – Sos Oct 24 '19 at 14:12

0 Answers0