简体   繁体   English

如何禁止IPython启动消息?

[英]How do I suppress the IPython startup message?

When debugging, I often drop into an IPython shell for interactive code testing. 在调试时,我经常会进入一个IPython shell进行交互式代码测试。 However this also causes a large info dump of the python version, date and help instructions to stdout. 但是,这也会导致python版本,日期和帮助指令的大型信息转储到stdout。 How can I suppress this information so it doesn't obscure the intentional debugging messages? 如何抑制此信息,以免模糊故意调试消息?

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

This code gives output like this... 这段代码给出了这样的输出......

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]:

You can do this: 你可以这样做:

IPython.embed(banner1="")

Setting banner1 to empty string would make the startup messages go away. banner1设置为空字符串会使启动消息消失。 It will not actually remove the messages but will replace them with empty strings. 它实际上不会删除消息,但会用空字符串替换它们。

You can also add useful messages using the banner1 , banner2 and exit_msg parameters: 您也可以通过增加有用信息banner1banner2exit_msg参数:

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

If you ever need to launch IPython instance from the command line, you can do this: 如果您需要从命令行启动IPython实例,则可以执行以下操作:

ipython --no-banner

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

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