但未显示在PyCharm中

但未显示在PyCharm中

本文介绍了输出显示在Jupyter Notebook中,但未显示在PyCharm中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过类似的帖子,但没有看到任何能真正解决Jupyter Notebook和PyCharm之间输出差异的答复.

I've seen similar posts but haven't seen any reply that really addresses the difference in outputs between Jupyter Notebook and PyCharm.

一个例子是这样的:

from datetime import datetime
now = datetime.now()
now

输出:
Jupyter笔记本:datetime.datetime(2019, 12, 8, 13, 20, 37, 339795)

Output:
Jupyter notebook: datetime.datetime(2019, 12, 8, 13, 20, 37, 339795)

Pycharm:Process finished with exit code 0

PyCharm中没有显示输出.有人可以解释为什么两者的输出有差异吗?我可以在PyCharm中看到相同的输出吗?

There is no output shown in PyCharm. Could someone please explain why there is a difference in the outputs of these two? Any way I can see the same output in PyCharm?

推荐答案

原因是因为Pycharm在脚本模式下运行,而Jupyter在交互模式下运行.您可以添加打印语句,例如print(now)来查看输出,也可以在Pycharm交互式解释器中运行代码.

The reason is because Pycharm is running in script mode, while Jupyter is working in interactive mode. You can add print statements such as print(now) to see the output, or you can run the code in the Pycharm interactive interpreter.

有关交互式模式的更多详细信息,请参见交互式模式和脚本模式下的Python解释差异

See this for more details on interactive mode Python interpretation difference in interactive mode and script mode

有关如何使用Pycharm交互式解释器的更多详细信息,请参见 Pycharm是否具有Interactive Python Interpreter?

See this for more details on how to use the Pycharm interactive interpreter Does Pycharm have Interactive Python Interpreter?

这篇关于输出显示在Jupyter Notebook中,但未显示在PyCharm中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:19