How do I print colored output to the terminal in Python?

前端 未结 7 1057
日久生厌
日久生厌 2020-12-04 17:55

Is there any python equivalent for perl\'s

print color \'red\';
print ;
print color \'reset\';

available in python?

<
7条回答
  •  感动是毒
    2020-12-04 18:19

    Color_Console library is comparatively easier to use. Install this library and the following code would help you.

    from Color_Console import *
    ctext("This will be printed" , "white" , "blue")
    The first argument is the string to be printed, The second argument is the color of 
    the text and the last one is the background color.
    

    The latest version of Color_Console allows you to pass a list or dictionary of colors which would change after a specified delay time.

    Also, they have good documentation on all of their functions.

    Visit https://pypi.org/project/Color-Console/ to know more.

提交回复
热议问题