waitingkuo
waitingkuo

Reputation: 93754

iPython didn't catch the empty line as a `\n`

It works in normal python interactive mode:

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

However, the second \n is gone in iPython

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

What's wrong?

Upvotes: 6

Views: 111

Answers (1)

waitingkuo
waitingkuo

Reputation: 93754

Finally I found that it's been solved in the newest version. Here's the committing

The reason is that while IPython use raw_input to capture what use type, the \n is being stripped. And then the string will be append a '\n' later. However, if the string is an empty string, it'll be thrown out. The flow is like:

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

Upvotes: 2

Related Questions