Can I write italics to the Python shell?

user1852430 picture user1852430 · Nov 26, 2012 · Viewed 37.2k times · Source

Is it possible to write something like this:

>>> text_output = "Hello World."
>>> print text_output

...where if the text_output is printed to the Python Shell, it is printed in italics?

Answer

John La Rooy picture John La Rooy · Nov 26, 2012

In Python 2 or 3 if your console supports italics, e.g. rxvt-unicode you can precede your Italic text with the ansi escape code for italics \x1B[3m, and then append it with \x1B[0m for reset/normal to return to normal characters.

>>> print("Normal text \x1B[3mitalic text\x1B[0m normal text")

The above code executing and printing italics