Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Python interactive prompt ">>>"

Tags:

I recall reading, in the Python 3.5 docs, how to change the >>> on the Python interactive prompt, such as how calling help() will change it to help>.

But for some reason, when I've gone back to try and remember, I just can't find the instructions to it. Does anyone know if this is possible?

like image 972
MutantOctopus Avatar asked Nov 13 '15 00:11

MutantOctopus


People also ask

How do I get out of interactive mode in Python?

Go to File -> New Window (Ctrl+N) and a window where you can write your program will pop up.

What is interactive prompt in Python?

The Python interactive console (also called the Python interpreter or Python shell) provides programmers with a quick way to execute commands and try out or test code without creating a file.

Can Python be used interactively?

There are two modes through which we can create and run Python scripts: interactive mode and script mode. The interactive mode involves running your codes directly on the Python shell which can be accessed from the terminal of the operating system.


1 Answers

You remember correctly.

It's in the sys module (sys.ps1 & sys.ps2):

Strings specifying the primary and secondary prompt of the interpreter. These are only defined if the interpreter is in interactive mode. Their initial values in this case are '>>> ' and '... '. If a non-string object is assigned to either variable, its str() is re-evaluated each time the interpreter prepares to read a new interactive command; this can be used to implement a dynamic prompt.

For example:

    >>> import sys    >>> sys.ps1 = "3.5>>> "    3.5>>> sys.ps2 = "3.5... "    3.5>>> 
like image 82
Gerrat Avatar answered Oct 01 '22 10:10

Gerrat