![](/img/trans.png)
[英]How to write a script bash to enter multi-line input in jupyter-notebook?
[英]How to copy paste multi-line text input without arbitrarily adding `\n` in jupyter-notebook?
我正在嘗試從 jupyter-notebook 單元格獲取交互式多行用戶輸入,如下所示:
contents = []
while True:
line = input()
if line:
contents.append(line)
else:
break
input_text = "\n".join(contents)
輸入文本示例:
This is a multi-line input.
It is good to put several lines after each other.
The reason of this is a good indentation.
One can use both tabs and spaces.
但是,當我從某處復制粘貼多行輸入而不是手動逐行傳遞時,它會連接成一個空格分隔的字符串,如下所示:
如何建立復制粘貼多行文本輸入而不在每行后任意添加\n
?
如果您能夠通過添加 '\r\n' 或其他可以在之后拆分的預定義分隔符來預處理用戶輸入,則可能會出現骯臟的解決方法
This is a multi-line input.\r\n
It is good to put several lines after each other.\r\n
The reason of this is a good indentation.\r\n
One can use both tabs and spaces.
你可以使用解碼
print(input().encode().decode('unicode_escape'))
結果 output:
This is a multi-line input.
It is good to put several lines after each other.
The reason of this is a good indentation.
One can use both tabs and spaces.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.