Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中没有输出,但jupyter笔记本中有输出_Python_Jupyter Notebook_Output_Jupyter - Fatal编程技术网

python中没有输出,但jupyter笔记本中有输出

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输出有什么奇怪的东西以及

运行以下代码

以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输出有什么奇怪的东西以及如何防止呢?

我不熟悉jupyter,但是如果它是一个REPL,在表达式求值时打印结果,那么它就是打印
fh.write
的返回值
write
返回写入的字符数,以便打印出来

\=fh.write
阻止输出,因为
=
是一条计算结果不为值的语句。您还可以通过执行类似于
fh.write(…)的操作来防止输出;无
。我不建议在实际代码中这样做,但为了限制输出,这可能是有益的