python - 如何悄悄启动Python REPL?

标签 python stdout ipython startup

有没有办法安静地启动 python,也许是通过设置一些环境变量或提供命令行选项?而不是看到这个:

wim@SDFA100461C:/tmp$ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

有时我想要这种行为,直接提示:

wim@SDFA100461C:/tmp$ python
>>> 

我也对 ipython 的答案感兴趣。

最佳答案

这似乎可以解决问题:

C:\Users\Bartek>python -i -c ""
>>> print "I ♥ Python!"
I ♥ Python!
>>> exit()

C:\Users\Bartek>

-i 选项描述为:

-i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x

所以只要你在终端上,它似乎没有任何警告。

ipython 有一个简单的 --no-banner 选项:

C:\Users\Bartek>ipython --no-banner

In [1]: print "I <3 Python!"
I <3 Python!

In [2]: exit()

C:\Users\Bartek>

虽然它似乎不支持 Unicode ;)

关于python - 如何悄悄启动Python REPL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948349/

相关文章:

jupyter-notebook - 在 IPython 中混合 shell 变量和 python 变量 '!command'

ipython - 在 ipython 中使用魔法 %paste 时,如何让它只粘贴复制的代码,而不是粘贴和执行,以便可以对其进行编辑

python - 使用模拟对象的困境

windows - IDE 崩溃后读取控制台应用程序的标准输出

python - 如何使用 python 代码在 jupyter 笔记本中保存 ipython 小部件的状态

python - 解析命令调用的输出

c - 在可移植 C 中将标准输出移出控制台

java - 为什么 CLASSPATH 对于 Python 失败但对于 RazorSQL 却有效?

python - 从 django 查看脚本运行 linux 命令

Python列表 |如何删除列表中的括号、引号和逗号?