指点成金-最美分享吧

登录

python终端彩色打印(termcolor)

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了python终端彩色打印(termcolor)相关的知识,希望对你有一定的参考价值。

Quick method for creating coloured tty in python terminal using 'termcolor'

$ pip install termcolor;
  1. try:

  2. import termcolor

  3. from termcolor import colored

  4. except: print "No colours :("

  5.  

  6. def p(*args, **kargs):

  7. color = kargs.get("color", None)

  8.  

  9. if color and termcolor:

  10. for x in args:

  11. sys.stdout.write(colored(x, color) + "")

  12. else:

  13. sys.stdout.write(*args)

以上是关于python终端彩色打印(termcolor)的主要内容,如果未能解决你的问题,请参考以下文章