Change shell print color in python 3.3.2

后端 未结 4 1808
太阳男子
太阳男子 2021-01-15 02:20

Is there any way to change shell print color in python 3.3.2 in Linux and Windows shell? I\'ve read all other topics but none of them working with this version or I should i

4条回答
  •  抹茶落季
    2021-01-15 02:56

    These will work on Linux and Mac, but not Windows. I reference them whenever I need to colorize my output.

    The first shows how to change the color.

    # snippet found at http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python
    
    class bcolors:
        WARNING = '\033[95m'
        ENDC = '\033[0m'
    
    print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)
    

    The second shows how each value displays in your environment.

    for i in range(0, 128):
        print("\033[%imThis is text!!\t\t( \\033[%im )\033[0m" % (i, i))
    

提交回复
热议问题