python-3.x - Jupyter Notebook 拒绝打印一些字符串

标签 python-3.x jupyter-notebook

一些 print() 输出被丢弃在我的笔记本中,但我看不到任何特定的模式或原因:

s = 'https://ad.doubleclick.net/'
t = 'ttps://ad.doubleclick.net/'
u = 'https://ad.doubleclick.net'
v = 'https://ad.doublclick.net/'
w = 'https://pubads.g.doubleclick.net/gampad/ads?caps'

for string in [s, t, u, v]:
    print('str:', string)
    print('repr(str):', repr(string))
    print()

输出:

str: 
repr(str): 'https://ad.doubleclick.net/'

str: ttps://ad.doubleclick.net/
repr(str): 'ttps://ad.doubleclick.net/'

str: https://ad.doubleclick.net
repr(str): 'https://ad.doubleclick.net'

str: https://ad.doublclick.net/
repr(str): 'https://ad.doublclick.net/'

str: 
repr(str): 'https://pubads.g.doubleclick.net/gampad/ads?caps'

我的第一行和最后一行 str: 发生了什么? 仅发生在笔记本中,在终端中运行 python 解释器不会出现此问题。

Python 3.8.5

> which jupyter
/Library/Frameworks/Python.framework/Versions/3.8/bin/jupyter

> jupyter --version
Selected Jupyter core packages...
IPython          : 8.0.0
ipykernel        : 6.7.0
ipywidgets       : 7.7.1
jupyter_client   : 7.1.1
jupyter_core     : 4.9.1
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.5.10
nbconvert        : 6.4.0
nbformat         : 5.1.3
notebook         : 6.4.7
qtconsole        : not installed
traitlets        : 5.1.1

最佳答案

不完全是一个答案,但这是 Jupyter Notebook 检查字符串变量是否是 URL 的结果,如果是,则将它们变成输出区域中的可点击链接。单元格的输出呈现在 <pre> 内标签,看起来像这样:

<pre>
str: <a target="_blank" href="https://ad.doubleclick.net/">https://ad.doubleclick.net/</a>
repr(str): 'https://ad.doubleclick.net/'

str: ttps://ad.doubleclick.net/
repr(str): 'ttps://ad.doubleclick.net/'

str: <a target="_blank" href="https://ad.doubleclick.net">https://ad.doubleclick.net</a>
repr(str): 'https://ad.doubleclick.net'

str: <a target="_blank" href="https://ad.doublclick.net/">https://ad.doublclick.net/</a>
repr(str): 'https://ad.doublclick.net/'

str: <a target="_blank" href="https://pubads.g.doubleclick.net/gampad/ads?caps">https://pubads.g.doubleclick.net/gampad/ads?caps</a>
repr(str): 'https://pubads.g.doubleclick.net/gampad/ads?caps'
</pre>

现在,某些链接未出现的事实不是 Jupyter Notebook 问题,您可以尝试在类似 https://html.onlineviewer.net 的网站上呈现此 HTML并看到同样的问题。但对我来说,这个问题只发生在 Firefox 中,而不是我检查的其他两个浏览器(Safari 和 Chrome)中。由于我找不到任何有关此行为的讨论,因此我在 Bugzilla here 上开了一张票。 .

关于python-3.x - Jupyter Notebook 拒绝打印一些字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73377504/

相关文章:

python - Jupyter 笔记本 : (OperationalError ('disk I/O error' , ))

python - pandas dataframe .loc 行值

python - input() 函数对我不起作用(Python 3.3)

python - "Session/line number was not unique in database."错误与Python代码的依赖关系

python - 美丽汤 : how to find all elements 2nd parent of which has exact attribute?

python - 在 Flask 中执行 app.run(debug=True) 行时出错

python - 在 Ubuntu 14.04 中使用 pip 安装 Jupyter Notebook

html - 如何创建一个看起来像 Python 笔记本的网页?

python - wxPython,按钮大小不起作用

python-3.x - 如何从不断刷新网页元素的网页中循环元素