简体   繁体   English

输出显示在 Jupyter Notebook 中但不在 PyCharm 中

[英]Output shown in Jupyter Notebook but not in PyCharm

I've seen similar posts but haven't seen any reply that really addresses the difference in outputs between Jupyter Notebook and PyCharm.我看过类似的帖子,但没有看到任何真正解决 Jupyter Notebook 和 PyCharm 之间输出差异的回复。

An example is like this:一个例子是这样的:

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

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

Pycharm: Process finished with exit code 0 Pycharm: Process finished with exit code 0

There is no output shown in PyCharm. 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 中看到相同的输出?

The reason is because Pycharm is running in script mode, while Jupyter is working in interactive mode.原因是因为 Pycharm 是在脚本模式下运行的,而 Jupyter 是在交互模式下工作的。 You can add print statements such as print(now) to see the output, or you can run the code in the Pycharm interactive interpreter.您可以添加诸如print(now)类的打印语句来查看输出,也可以在 Pycharm 交互式解释器中运行代码。

See this for more details on interactive mode Python interpretation difference in interactive mode and script mode有关交互模式的更多详细信息,请参阅this交互模式和脚本模式中的 Python 解释差异

See this for more details on how to use the Pycharm interactive interpreter Does Pycharm have Interactive Python Interpreter?有关如何使用 Pycharm 交互式解释器的更多详细信息,请参阅此处 Pycharm是否具有交互式 Python 解释器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM