6

When I open a python shell with python, can I have a colored output? For example red errors like you are used from IDEs?

>>> 10 * (1/0)
Traceback (most recent call last):
  FIle "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
>>> 

I both read man python and python --help, but didn't find anything regarding colours so I assume that there is nothing by default, but is it achievable anyway?

2
  • BTW: Of course I didn't require a syntax highlightning like in the example above. askubuntu colored it like that. (I don't think colour in std.in is possible) Nov 26, 2015 at 10:11
  • Colouring your input is possible depending on the application. For example, the zsh and fish shells support it. But Python's shells don't provide any mechanism I know of, which supports it.
    – muru
    Nov 26, 2015 at 10:37

1 Answer 1

10

Use IPython for an enhanced Python interactive shell.

sudo apt-get install ipython     # Python 2
sudo apt-get install ipython3    # Python 3

For example:

enter image description here

IPython has other useful features, such as a browser-based interface.

3
  • Ok, that's a nice tool. Especially the repetiton of the whole command with the arrow-keys since I am a beginner with python... Nov 26, 2015 at 10:08
  • @h0ch5tr4355 Were you using python2? python3's shell has the arrow-key-history feature.
    – muru
    Nov 26, 2015 at 10:12
  • 1
    Yes I have python2. In the normal shell (python) I can repeat only 1 line, never a whole command over multiple lines such as a loop Nov 26, 2015 at 10:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .