mar tin mar tin - 1 year ago 125
Python Question

Python: printing in color and with style

If I want to print colored 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 color 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