首页 > 解决方案 > 如何在 Zeppelin 中的 Python Pyspark 中打印粗体 - 以及在 Zeppelin 中使用 python-print-function 的其他格式

问题描述

我在 Windows 桌面上使用 Zeppelin 中的 python,Zeppelin 安装在 Linux 机器上,并希望在“%pyspark”单元格中打印一些粗体。

print('\033[1m' + 'Hello' + '\033[0m')

在 Jupyter 环境中工作,但在 Zeppelin 中,我只是在白色背景上得到一个不粗体的白色字体。(我可以通过标记文本来看到这一点。)

此外,我可能会使用降价语言。但随后我将不得不使用单独的单元格,并且无法将文本与 python 结果结合起来。

我还能尝试什么?

标签: pythonpysparkapache-zeppelin

解决方案


在 Zeppelin 中,您可以像这样使用 html 来获取粗体文本:

print( '%html <b> hello </b>')

你好

只需在第一个引号后以“%html”开头,然后您可以使用 html 语法直到第二个引号。

对于那些还没有大量使用 HTML 的人,这里有一些更多的 HTML 基础知识以及如何在 %pyspark - Zeppelin 单元中使用它们:

其他文字样式

print('%html <strong>important</strong>')
print('%html <i>italic</i>')
print('%html <del>striked through</del>')
print('%html <sub>low</sub>')
print('%html <sup>high</sup>')

为了:

重要的 斜体 击穿

以下在 Zeppelin 中也可以正常工作,但我现在无法展示它:

print('%html <ins>underlined</ins>')
print('%html <mark>marked</mark>')
print('%html <small>small</small>')

您可以使用 h1, h2,...,h6 作为标题

print('%html <h1>Heading 1</h1>')

标题 1

无序或有序列表:

print( '%html <ul>  <li>something</li>  <li>anything</li> </ul>  ')
print( '%html <ol>  <li>first</li>  <li>second</li> </ol>  ')
  • 某物
  • 任何事物
  1. 第一的
  2. 第二

链接:

 print('%html print <a href="https://www.stackoverflow.com">This is a link to stackoverflow.com</a> ')

这是指向 stackoverflow.com 的链接

将鼠标移到原始单词上时出现的缩写或信息文本。

print('%html <p><abbr title="Hypertext Markup Language">HTML</abbr> is the standard markup language for creating web pages and web applications.</p>')

您可以在 Zeppelin 中尝试一下。

文字颜色

例如,基于 rgb 颜色空间,其中 r,g,b 是颜色中红色、绿色和蓝色的数量:

print('%html <p style="color:rgb(255, 0, 0);">red</p>')
print('%html <p style="color:rgb(0, 255, 0);">green</p>')
print('%html <p style="color:rgb(0, 0, 255);">blue</p>')

颜色代码的一些示例

您也可以为背景着色:

print('%html <p style="background-color:rgb(255, 0, 0);">Background is red</p>')

推荐阅读