zoukankan      html  css  js  c++  java
  • python colorama 模块

    colorama是一个python专门用来在控制台、命令行输出彩色文字的模块,可以跨平台使用。

    1. 安装colorama模块

    pip install colorama

    可用格式常数:

    Fore:  BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
    Back:  BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
    Style: DIM, NORMAL, BRIGHT, RESET_ALL



    "from colorama import Fore,Back,Style" 后使用Fore、Back、Style的常数+文本来使用:
    from colorama import Fore,Back,Style
    print (Fore.RED + "some red text")
    print (Back.GREEN + "and with a green background")
    print (Style.DIM + "and in dim text")
    print (Style.RESET_ALL)
    print ("back to normal now!!")

    初始化并设置是否自动恢复

    init(autoreset = True):
    init(autoreset = False):

    # 如果未设置autoreset=True,需要使用如下代码重置终端颜色为初始设置
    #print(Fore.RESET + Back.RESET + Style.RESET_ALL)

     

    实列如下:

     效果:

    若要想让第二行颜色不是之前设置的红色就需要这样操作:


     效果:

  • 相关阅读:
    javaee_正则表达式基础和常用表达式
    hello2源代码分析
    servlet_filterj简介
    hello1的web.xml解析
    Annotation
    注入(Injection)
    容器(Container)
    Building Tool(Maven/Gradle)
    JavaWeb的历史与发展趋势
    Build Tools
  • 原文地址:https://www.cnblogs.com/webcyz/p/15675762.html
Copyright © 2011-2022 走看看