views:

46

answers:

3

Usually the Python console looks like this:

>>> command

Is there a way to make it look like:

SomeText>>> command
+3  A: 
sys.ps1 == ">>>"
sys.ps2 == "..."

You can also change this in the PYTHONSTARTUP environment variable.

For example (this is not secure), put the following in a script somewhere and set PYTHONSTARTUP to point at that script.

import sys
import getpass
sys.ps1  = getpass.getuser( ) + ">>> "

Of course, you could change the last line above to anything you want.

katrielalex
+1  A: 

You could try

import sys
import os

sys.ps1 = os.getenv("USER") + sys.ps1

(or getpass.getuser() as suggested by the other answer)

In the corrected version, it's even easier, of course:

import sys
sys.ps1 = "SomeText" + sys.ps1
Andrew Jaffe
I corrected the question. I don't necessary want to display the user name. Just a custom text for making some personalized screenshots.
campuscodi
A: 

IPython provides convenient way of setting sophisticated prompts as described here.

cji