How to print colored text in Python?

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

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

30条回答
  •  醉酒成梦
    2020-11-21 05:10

    YAY! another version

    while i find this answer useful, i modified it a bit. this Github Gist is the result

    usage

    print colors.draw("i'm yellow", bold=True, fg_yellow=True)
    

    enter image description here

    in addition you can wrap common usages:

    print colors.error('sorry, ')
    

    asd

    https://gist.github.com/Jossef/0ee20314577925b4027f

提交回复
热议问题