How to print colored text in Python?

前端 未结 30 2845
谎友^
谎友^ 2020-11-21 04:41

How can I output colored text to the terminal in Python?

30条回答
  •  既然无缘
    2020-11-21 05:16

    I ended up doing this, I felt it was cleanest:

    formatters = {             
        'RED': '\033[91m',     
        'GREEN': '\033[92m',   
        'END': '\033[0m',      
    }
    
    print 'Master is currently {RED}red{END}!'.format(**formatters)
    print 'Help make master {GREEN}green{END} again!'.format(**formatters)
    

提交回复
热议问题