我在哪里可以找到加载到Python shell中的第一个文本并进行更改?

当我打开IDLE或在cmd中加载Python时加载此文本:

Python 3.4.3(v3.4.3:9b73f1c3e601,2015年2月24日,22:43:06)[win32上的MSC v.1600 32位(Intel)]请输入“copyright”,“credits”或“license()”信息。

我在哪里可以找到该文件并更改文本,或者改为加载脚本?


我不知道有什么方法可以在不修改/重新编译python二进制文件的情况下更改默认文本,但似乎可以使用环境变量PYTHONSTARTUP来通过带print命令的python文件添加其他文本。 您也可以更改此文件中的提示字符串。 例如:

在我的.bashrc中:

export PYTHONSTARTUP=/home/jake/.mypythonstartup

/home/jake/.mypythonstartup:

import sys
print("Welcome, master!")
sys.ps1 = "How may I serve you? "
sys.ps2 = "                 ... "

结果:

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Welcome, master!
How may I serve you? def test():
                 ...     print("test")
                 ...
How may I serve you? test()
test
How may I serve you? 

关于PYTHONSTARTUP文档可以在这里找到:https://docs.python.org/3/tutorial/appendix.html#the-interactive-startup-file


基于对idlelib源代码的快速idlelib ,您可以执行如下操作:

from code import interact
interact("Welcome master.")

正在使用:

$ python idle2.py
Welcome master.
>>> print 'foo'
foo

您也可以使用命令行标志来运行命令,然后进入交互模式:

$ python -ic "print 'Welcome master.'"
Welcome master.
>>> 
链接地址: http://www.djcxy.com/p/48667.html

上一篇: Where can I find the first text that loads in the Python shell and change it?

下一篇: How to run Pip commands from CMD