[IPython-dev] Ipython Notebook Showing Warnings In Wrong Order

Matthias Bussonnier bussonniermatthias at gmail.com
Thu Jun 12 02:57:28 EDT 2014


Hi Justin, 

Le 12 juin 2014 à 07:34, Justin a écrit :

> The order that warning messages are printed in Ipython Notebooks in the presence of a print statement is not as expected. Take for example:

No the order is not wrong, warning send string to stderr, print to stdout. 
Nothing guaranties the "order" in which they appear.

Having them interleaved in the terminal is one way of  representing it to the user when you only have on text buffer.

If you do care about the order, you should explicitly write to stout or err with both.

Here is an example in python 3, or python  2 if you import print_function from __future__.
It does what you expect.

import warnings
import sys
warnings.simplefilter('always')
for x in range(10):
    warnings.warn('Warning %d' % (x))
    print( x, file=sys.stderr)

-- 
M

> import warnings
> warnings.simplefilter('always')
> 
> for x in range(10):
>     warnings.warn('Warning %d' % (x))
>     print x

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140612/bb2d5f4a/attachment.html>


More information about the IPython-dev mailing list