Strange 'print' behavior in IPython in PyCharm

Viewed 320

The print function seems to reduce the number of dots when displayed:

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.22.0
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux

In [2]: s = "A\n..... a\n..... b\n"

In [3]: print(s)
A
.. a
.. b


In [4]: 

Nothing like this happens in the terminal:

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> s = "A\n..... a\n..... b\n"
>>> print(s)
A
..... a
..... b
>>> 

even if I run IPython in it:

$ ipython

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: s = "A\n..... a\n..... b\n"

In [2]: print(s)
A
..... a
..... b


In [3]: 

Does anyone know the reason for this behavior?

1 Answers

I think it's related to iPython syntax for implicit line join. PyCharm may convert the three dots into an ellipsis, and interpret it as a "new line command" (like when in ipython console you break line without closing parenthesis and it expect other arguments)

Related