Search code examples
pythonstringipythonnon-ascii-characters

String fails to paste in the new iPython 5.0


In the python 2.7 console, as well as iPython 4, I was able to paste this string into a variable like so:

In [2]: c = 'ÙjÌÉñõµÏ“JÖq´ž#»&•¼²nËòQZ<_'

Subsequently I could type:

In [3]: print(c) and it would return ÙjÌÉñõµ Ï“JÖq´ž#»&•¼²nËòQZ<_

However, in iPython 5.0, I get the following error:

In [4]: c = 'ÙjÌÉñõµ^LÏ“JÖq´ž#»&•¼²nËòQZ<_'
  File "<ipython-input-4-9bf9f2fa5210>", line 1
    c = 'ÙjÌÉñõµ

^
SyntaxError: EOL while scanning string literal

Even %paste returns an error:

    ÙjÌÉñõµ
    ^
SyntaxError: invalid syntax

What changed in iPython from 4 to 5, and why is this occurring? Something to do with the string not having escaped quotes?


Solution

  • http://blog.jupyter.org/2016/07/08/ipython-5-0-released/

    Ipython5 replaced the default readline with a new prompt_toolkit.

    It looks like your string has several characters that the old readline ignored, but the new one sees. The first occurs right after the µ. I don't see it in the SO windows, but I can 'feel it' when moving the cursor over the line. I can also see something when pasting the line into an editor. But I not familiar enough with raw text tools to see more.

    When I paste your string into a plain Python shell I get a bell and the screen clears. So even the regular readline is having problems with this string.

    I've added '|' were there are unprintable characters

    c = 'ÙjÌÉñõµ|Ï“JÖq´ž#|»&•¼|²nËòQZ<_'