Where can I find the first text that loads in the Python shell and change it?
This text loads when I open IDLE or load Python in cmd:
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
Where can I find the file and change the text or make a script load instead?
I don't know of any way to change the default text without modifying/recompiling the python binary, but it seems you can use the environment variable PYTHONSTARTUP
in order to add additional text via a python file with print
commands. You can also change the prompt strings in this file. For example:
in my .bashrc:
export PYTHONSTARTUP=/home/jake/.mypythonstartup
/home/jake/.mypythonstartup:
import sys
print("Welcome, master!")
sys.ps1 = "How may I serve you? "
sys.ps2 = " ... "
Result:
$ 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?
Documentation on PYTHONSTARTUP
can be found here: https://docs.python.org/3/tutorial/appendix.html#the-interactive-startup-file
Based on a quick snoop around the idlelib
source code, you could do something like:
from code import interact
interact("Welcome master.")
In use:
$ python idle2.py
Welcome master.
>>> print 'foo'
foo
You could also use the command line flags to run a command then enter interactive mode:
$ python -ic "print 'Welcome master.'"
Welcome master.
>>>
链接地址: http://www.djcxy.com/p/48668.html