IPython did not catch the empty string as `\ n`

It works in normal python interactive mode:

>>> """1 ... ... 2""" '1\n\n2' 

However, the second \n missing in iPython

 In [4]: """1 ...: ...: 2""" Out[4]: '1\n2' 

What's wrong?

+6
source share
1 answer

Finally, I found that it was resolved in the newest version. Here commit

The reason is that while IPython use raw_input to fix the type of use, \n loses. And then the line will add "\ n" later. However, if the string is an empty string, it will be discarded. The stream is as follows:

 if not s: return s = s+'\n' 
+2
source

Source: https://habr.com/ru/post/945219/


All Articles