【发布时间】:2023-03-31 04:22:01
【问题描述】:
我正在尝试在 Jupyter Notebook 中漂亮地打印一个字典。
我正在使用以下内容:
import pprint
stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
stuff.insert(0, stuff[:])
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(stuff)
但是按 shift+enter 后,没有出现 [out] 单元格(即我看不到漂亮的打印输出)
知道为什么会这样/我应该改变什么才能看到漂亮的打印输出吗?
编辑:实际上这是一个 python 2.7 问题 - 它在 3.x 中运行良好。 有没有人在 python 2.7 上试过并看到它工作?
【问题讨论】:
-
相同的代码对我来说很好用。我正在使用 Python 3.6
-
@Ujjwal 哦,我明白了 - 我正在使用 2.7...你知道 2.7 中的 coreect 语法是什么吗?
-
我在try.jupyter.org 上测试了你的代码,它确实显示了输出。
-
你可以尝试输出 html,随心所欲:stackoverflow.com/questions/25698448/…
-
@jimbasquiat 是的,它适用于 2.7
标签: python python-2.7 jupyter-notebook python-2.x pretty-print