martina martina - 1 year ago 89
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?

Answer Source

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')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download