I’m attempting to colorize my python interpreter to help visually separate text noise.
So if I start interactive python it gives me plain text. I can do this:
import sys
sys.ps1 = "\033[0;34m>>> \033[0m"
sys.ps2 = "\033[1;34m... \033[0m"
However if I exit the interpreter and go back in the values revert to their default, which isn’t surprising in the slightest. My question is how would I save these values and use them as the default?
If the environment variable
PYTHONSTARTUPis defined when Python starts (in interactive mode), Python will read and execute that file. Look at theENVIRONMENT VARIABLESsection of this document for more information.So if you put your
sys.ps1commands into~/.pythonrc.pyand pointedPYTHONSTARTUPat that file……you would be all set.
You may also want to check out ipython, which is a Python interactive interpreter with all sorts of fancy features and customization possibilities.