i heard of code to make text bold or underlined, but is there code to make text italics?
here’s the code that i saw
`
class color:
PURPLE = ‘\033[95m’
CYAN = ‘\033[96m’
DARKCYAN = ‘\033[36m’
BLUE = ‘\033[94m’
GREEN = ‘\033[92m’
YELLOW = ‘\033[93m’
RED = ‘\033[91m’
BOLD = ‘\033[1m’
UNDERLINE = ‘\033[4m’
END = ‘\033[0m’
print color.BOLD + ‘Hello World !’ + color.END
`
1 Like
As far as Python is concerned, that’s just text. But yes, some terminal emulators support italics, the escape sequence for that is \e[3m
There are some packages for colorizing output, I did a quick google search and there’s one called “colorama” which is supposedly cross-platform so that’s probably a good start.
colorama can be installed with pip, and there are some demo files in its source: https://github.com/tartley/colorama/tree/master/demos
2 Likes
@johnhon,
found an article on stackoverflow.com
that may be of interrest to you
google search
== discussions / opinions ==
how determine the terminal type in python site:stackoverflow.com
http://stackoverflow.com/questions/7445658/how-to-detect-if-the-console-does-support-ansi-escape-codes-in-python
1 Like
i forgot to actaully mention my final intent. i wish to copy the output and be able to paste it in word (already got that sorted but it isnt italic). is there some way in which the copied text was turned into italics or just some fancy formatting option?
There’s a package for editing docx files, dealing with some clipboard-application/the OS sounds very platform-dependent and a bunch of extra challenges.
https://python-docx.readthedocs.org/en/latest/
python-docx is a Python library for creating and updating Microsoft Word (.docx) files.
2 Likes