user1852430
user1852430

Reputation: 171

Can I write italics to the Python shell?

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?

Upvotes: 17

Views: 61786

Answers (4)

user23047726
user23047726

Reputation: 1

Powershell can print Italics.

CMD cannot. CMD can't do ANYTHING(it's like 25 years old, what can you expect).

This works great: print("\x1B[3mThis text\x1B[0m is \x1B[3mitalicized!\x1B[0m")

Upvotes: 0

John La Rooy
John La Rooy

Reputation: 304137

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

Upvotes: 30

BrenBarn
BrenBarn

Reputation: 251355

Not in the standard Python shell, no. If you want all output text to be in italics, you could use some GUI shell like Dreampie. If you want the ability to actually style text (with italics, bold, etc.), you need to use some GUI library that provides that sort of ability.

Upvotes: 1

Yuushi
Yuushi

Reputation: 26040

No. The print function outputs to sys.stdout by default. Assuming you're using something like IDLE, this will simply be echoed into IDLE. You can set some options in IDLE itself to show different font faces and sizes and whatnot, but this will modify everything, not just the output of print commands.

Upvotes: -1

Related Questions