python常用颜色表示_python 命令行常用字体颜色

python 命令行常用字体颜色

在平时工作中经常会使用python脚本编写一些程序或工具,经常需要在控制台输出一些信息,例如:请输入用户名、密码等。如果用户名不合法输出‘用户名不规范’等提示信息。但这样输出的字体颜色都是白色,不容易区分重要的提示信息,所以我们可以参考linux命令行的提示。

代码如下,拿走不谢!

class Color(object):

GREEN = '\033[92m'

YELLOW = '\033[93m'

RED = '\033[91m'

BlUE = '\033[94m'

END = '\033[0m'

@classmethod

def red(cls, string):

return cls.RED + string + cls.END

@classmethod

def green(cls, string):

return cls.GREEN + string + cls.END

@classmethod

def yellow(cls, string):

return cls.YELLOW + string + cls.END

@classmethod

def cyan(cls, string):

return cls.BlUE + string + cls.END

if __name__ == '__main__':

green = Color.green('this is green, such as ....ok')+' over'

red = Color.red('this is red, such as error:xxxxxx')+' over'

yellow = Color.yellow('this is yellow, such as warning........')+' over'

blue = Color.cyan('this is blue, such as, information')+' over'

print(green)

print(red)

print(yellow)

print(blue)

/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值