Issue
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).
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.', '...']
EDIT: As @user2357112 pointed out in the comments and in their answer changing the prompt does not affect this. Here it seemed to work because adding more lines to the beginning of the cell make Ipython interpreter think they are no longer part of the prompt. You can change your string to '\n...\n.o.\n...'
as a workaround.
Answered By - Asocia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.