martina martina - 9 months ago 45
Python Question

Python: printing in colour and with style

If I want to print coloured text, I would just do, using codes

green = '\033[0;32m'
print green + 'Hello'

and that gives me green text. If I want to have bold text, I would just use the code for bold, which is

Now, I tried to combine them as

print bold + green + 'Hello'

is the aforementioned code, and that didn't work, gave me just green text with no bold style.

Anyway, what am I missing to combine colour with style?


I can recommand this gist by Diego Navarro Mellén.

You can combine whatever you like when doing something like this:

with pretty_output(BOLD, FG_GREEN) as out:
    out.write('This is a bold text in green')