Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does splitlines() not give the expected result for triple dots in Jupyter?

I believe the following code

s = '''
...
.o.
...
'''
print(s.splitlines())

should print

['', '...', '.o.', '...']

Indeed, this is the case when Python is executed normally (example run on Wandbox is here).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But the reality is ruthless (as usual); Google Colaboratory prints a result without "triple dots":

I also tried the same code with a locally installed Jupyter (Python 3.7.13, Jupyter notebook 6.4.12, IPython 7.34.0) and it gave me the same result as Google Colaboratory.

Does anyone know what causes this deletion of the triple dots?

>Solution :

Google collab interprets ... as part of the prompt. You can change the prompt to some other string and the result will be as you expected:

import sys
sys.ps2 = '<<<' # default value is ...

s = '''
...
.o.
...
'''
print(s.splitlines())
['', '...', '.o.', '...']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading