python - 如何抑制 IPython 启动消息?

标签 python ipython

调试时,我经常进入 IPython shell 进行交互式代码测试。然而,这也会导致 python 版本、日期和帮助说明的大量信息转储到标准输出。我如何才能抑制此信息,使其不会掩盖有意的调试消息?

x = get_important_data()
print 'important info! right here! The data is in variable "x"'
import IPython
IPython.embed()

这段代码给出了这样的输出...

important info! right here! The data is in variable "x"
Python 2.7.11 |Anaconda 2.4.0 (x86_64)| (default, Dec  6 2015, 18:57:58) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

最佳答案

你可以这样做:

IPython.embed(banner1="")

banner1 设置为空字符串会使启动消息消失。它实际上不会删除消息,但会用空字符串替换它们。

您还可以使用 banner1banner2exit_msg 参数添加有用的消息:

IPython.embed(
    banner1="Entering Debug Mode", 
    banner2="Here's another helpful message",
    exit_msg="Exiting the debug mode!"
)

如果您需要从命令行启动 IPython 实例,您可以这样做:

ipython --no-banner

关于python - 如何抑制 IPython 启动消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34798728/

相关文章:

python - Jupyter + PySpark 自动完成

ipython:启动时禁用版权和帮助

apache-spark - 使用 Spark 2 启动 Ipython

python - 如何从 Python 中的数据框中排除非数字整数

Windows 中的 Python 分析,如何忽略内置函数

python - 无法使用 tkinter 取消绑定(bind)函数

python - django admin 内联多对多自定义字段

python - Keras PREDICTION 抛出 'TypeError: ufunc ' add' 不包含签名匹配类型 dtype ('<U4' ) dtype ('<U4' ) dtype ('<U4' )' 的循环

python - 给定经纬度,根据经纬度的 json 列表找到最近的位置

python - numpy 阴影内置函数 : what is the fully qualified name for built in function?