如何stdout抑制输出?
例如,分号可用于抑制返回对象的显示
>>> 1+1
2
>>> 1+1; # No output!
Run Code Online (Sandbox Code Playgroud)
但是,打印到stdout的函数不受分号影响.
>>> print('Hello!')
Hello!
>>> MyFunction()
Calculating values...
Run Code Online (Sandbox Code Playgroud)
如何才能从输出print/ MyFunction被抑制?
我有一个我想在IPython中运行的Python脚本.我想将输出重定向(写入)到文件,类似于:
python my_script.py > my_output.txt
Run Code Online (Sandbox Code Playgroud)
当我在IPython中运行脚本时,我该怎么做呢,比如说 execfile('my_script.py')
有一个较旧的页面描述了可以编写的函数来执行此操作,但我相信现在有一种内置的方法来执行此操作,我找不到.
好吧,标题似乎对我来说足够了.我使用一些功能,在某些点打印控制台中的东西.由于我无法修改它们,我想知道在使用这些功能时是否存在不打印的解决方案.
非常感谢 !
尼科
我在jupyter笔记本中收到这个警告.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:10: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
# Remove the CWD from sys.path while we load stuff.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
# This is added back by InteractiveShellApp.init_path()
Run Code Online (Sandbox Code Playgroud)
这很烦人,因为它出现在我做的每一次跑步中:
我该如何修复或禁用它?