I use standard tips for customizing interactive Python session:
$ cat ~/.bashrc export PYTHONSTARTUP=~/.pystartup $ cat ~/.pystartup import os import sys import
I open info readline and found:
-- Function: int rl_expand_prompt (char *prompt) Expand any special character sequences in PROMPT and set up the local Readline prompt redisplay variables. This function is called by `readline()'. It may also be called to expand the primary prompt if the `rl_on_new_line_with_prompt()' function or `rl_already_prompted' variable is used. It returns the number of visible characters on the last line of the (possibly multi-line) prompt. Applications may indicate that the prompt contains characters that take up no physical screen space when displayed by bracketing a sequence of such characters with the special markers `RL_PROMPT_START_IGNORE' and `RL_PROMPT_END_IGNORE' (declared in `readline.h'. This may be used to embed terminal-specific escape sequences in prompts.
As say text I search for RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE definition in readline.h and found next:
/* Definitions available for use by readline clients. */ #define RL_PROMPT_START_IGNORE '\001' #define RL_PROMPT_END_IGNORE '\002'
So I put appropriate changes to my ~/.pystartup:
green='\001\033[32m\002' red='\001\033[31m\002' reset='\001\033[0m\002'
and now all work fine!!!
For a better python shell experience, I'd recommend you to use either ipython or bpython.