Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I write italics to the Python shell?

Tags:

python

italics

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?

like image 747
user1852430 Avatar asked Nov 26 '12 05:11

user1852430


1 Answers

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

like image 189
John La Rooy Avatar answered Sep 27 '22 19:09

John La Rooy