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

前端 未结 7 1040
日久生厌
日久生厌 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:21

    What about the ansicolors library? You can simple do:

    from colors import color, red, blue
    
    # common colors
    print(red('This is red'))
    print(blue('This is blue'))
    
    # colors by name or code
    print(color('Print colors by name or code', 'white', '#8a2be2'))
    

提交回复
热议问题