美文网首页
python_printf

python_printf

作者: lc_qiu | 来源:发表于2016-12-22 14:59 被阅读0次

    # -*- coding: utf-8 -*-

    """

    Spyder Editor

    This is a temporary script file.

    """

    import time

    with open('log.txt','w') as f:

    f.write(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))+'\n')

    #  格式:\033[显示方式;前景色;背景色m

    #  说明:

    #

    #  前景色            背景色            颜色

    #  ---------------------------------------

    #    30                40              黑色

    #    31                41              红色

    #    32                42              绿色

    #    33                43              黃色

    #    34                44              蓝色

    #    35                45              紫红色

    #    36                46              青蓝色

    #                      47              灰色

    #    37                48              白色

    #

    #  显示方式          意义

    #  -------------------------

    #      0          终端默认设置

    #      1            高亮显示

    #      4            使用下划线

    #      5              闪烁

    #      7            反白显示

    #      8              不可见

    #

    #  例子:

    #  \033[1;31;40m

    #  \033[0m          ]]]

    STYLE={

    'mode':{

    '正常':0,'高亮':1,'下划线':4,'闪烁':5,

    'default':0#'正常'

    },

    'fore':{

    '黑':30,'红':31,'绿':32,'黄':33,

    '蓝':34,'紫':35,'青':36,'白':37,

    'default':30#'黑'

    },

    'back':{

    '黑':40,'红':41,'绿':42,'黄':43,

    '蓝':44,'紫':45,'青':46,'灰':47,'白':48,

    'default':48#'白'

    }

    }

    def printf(str,fore='default',back='default',mode='default'):

    mode=STYLE['mode'][mode] if mode in STYLE['mode'].keys() else STYLE['mode']['default']

    fore=STYLE['fore'][fore] if fore in STYLE['fore'].keys() else STYLE['fore']['default']

    back=STYLE['back'][back] if back in STYLE['back'].keys() else STYLE['back']['default']

    style='\033[%s;%s;%sm' %(mode,fore,back)

    print(style+str+'\033[0m') #print('\033[0m') 重置

    #==============================================================================

    # def test():

    #    printf('THIS is a test',back='红')

    #    printf('THIS is a test',back='绿')

    #    printf('THIS is a test',back='黄')

    #    printf('THIS is a test',back='蓝')

    #

    # if __name__ == '__main__':

    #    test()

    #==============================================================================

    相关文章

      网友评论

          本文标题:python_printf

          本文链接:https://www.haomeiwen.com/subject/fcfhvttx.html