Is it possible to print using different colors in ipython's Notebook?

后端 未结 12 1168
孤独总比滥情好
孤独总比滥情好 2020-12-23 09:15

Is it somehow possible to have certain output appear in a different color in the IPython Notebook? For example, something along the lines of:

 print(\"Hello          


        
12条回答
  •  情歌与酒
    2020-12-23 09:59

    Taken from: Standard for ANSI Colors in Terminals

    This snippet can show you all the colors in one row:

    RESET = "\x1b[0m"
    print("To reset attributes: \\x1b[0m\n")
    for i in range(0, 8):
        print("\x1b[1;3{0}m\\x1b[1;3{0}m{1} \x1b[0;3{0}m\\x1b[0;3{0}m{1} "
              "\x1b[1;4{0};3{0}m\\x1b[1;3{0};4{0}m{1}".format(i, RESET))
    

提交回复
热议问题