python中没有输出,但jupyter笔记本中有输出
运行以下代码 以open('abc','wt')作为fh的python中没有输出,但jupyter笔记本中有输出,python,jupyter-notebook,output,jupyter,Python,Jupyter Notebook,Output,Jupyter,运行以下代码 以open('abc','wt')作为fh的: fh.write('\n'.join(['a','b','c'])) 在ipython中,没有预期的输出; 但是,在jupyter笔记本中,输出类似[Out 4]:5 这可能与 从IPython.core.interactiveshell导入interactiveshell InteractiveShell.ast\u node\u interactivity=“全部” 在jupyter。但是jupyter输出有什么奇怪的东西以及
:
fh.write('\n'.join(['a','b','c']))
在ipython
中,没有预期的输出;
但是,在jupyter
笔记本中,输出类似[Out 4]:5
这可能与
从IPython.core.interactiveshell导入interactiveshell
InteractiveShell.ast\u node\u interactivity=“全部”
在jupyter。但是jupyter输出有什么奇怪的东西以及如何防止呢?我不熟悉jupyter,但是如果它是一个REPL,在表达式求值时打印结果,那么它就是打印
fh.write
的返回值write
返回写入的字符数,以便打印出来
\=fh.write
阻止输出,因为=
是一条计算结果不为值的语句。您还可以通过执行类似于fh.write(…)的操作来防止输出;无
。我不建议在实际代码中这样做,但为了限制输出,这可能是有益的