• 20 python 初学(logging模块)


    学习网站:https://www.cnblogs.com/yuanchenqi/articles/5732581.html

    logging 模块:

    # _author: lily
    # _date: 2019/1/14
    import logging
    
    # logging.debug('debug message')
    # logging.info('info message')
    # logging.error('error message')
    # logging.warning('warning message')
    # logging.critical('critical message')
    
    # logging.basicConfig(level=logging.DEBUG,
    #                     format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
    #                     datefmt='%a,%d %b %Y %H:%M:%S',
    #                     filename='test.log',
    #                     filemode='w')
    #
    # #Mon,14 Jan 2019 23:23:11 learn_of_logging_module.py[line:17] DEBUG debug message
    # logging.debug('debug message')
    # logging.info('info message')
    # logging.error('error message')
    # logging.warning('warning message')
    # logging.critical('critical message')
    
    logger = logging.getLogger()
    # 创建一个handler,用于写入日志文件
    fh = logging.FileHandler('test.log')   # 文件对象
    # 在创建一个handler,用于输出到控制台
    ch = logging.StreamHandler()  # 屏幕对象
    
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    
    logger.addHandler(fh)
    logger.addHandler(ch)
    
    logger.setLevel(logging.DEBUG)
    
    logger.debug('debug message')
    logger.info('info message')
    logger.warning('warning message')
    logger.error('error message')
    logger.critical('critical message')
    View Code

    configparser块:

    # _author: lily
    # _date: 2019/1/15
    
    import configparser
    
    config = configparser.ConfigParser()
    config["DEFAULT"] = {'ServerAliveInterval': '45',
                         'Compression': 'yes',
                         'CompressionLevel': '9'}
    
    config['bitbucket.org'] = {}
    config['bitbucket.org']['User'] = 'hg'
    config['topsecret.server.com'] = {}
    topsecret = config['topsecret.server.com']
    topsecret['Host Port'] = '50022'  # mutates the parser
    topsecret['ForwardX11'] = 'no'  # same here
    config['DEFAULT']['ForwardX11'] = 'yes'
    with open('example.ini', 'w') as configfile:
        config.write(configfile)
    View Code

    re 模块:

    import re
    
    ret = re.findall('adc+?', 'adccc')   # ['abd']
    print(ret)
    
    
    ret = re.findall('(?P<name>w{2})(?P<age>d{2})', 'djkwif728372')
    print(ret)    # [('if', '72'), ('83', '72')]
    
    ret = re.search('(?P<name>w{2})(?P<age>d{2})', 'djkwif728372')
    print(ret.group('name'))   # if
    print(ret.group('age'))    # 72
    
    
    ret = re.findall('www.(w+).com', 'www.baidu.com')
    print(ret)   # ['baidu']  这是因为分组权限较高,只打印分组内的内容。如果想打印全部内容在括号内加上 ?:
    
    ret = re.findall('www.(?:w+).com', 'www.baidu.com')
    print(ret)   # ['www.baidu.com']
    View Code
    猪猪侠要努力呀!
  • 相关阅读:
    Android架构详解
    wince下实现GPRS上网,程序控制拨号 .
    wince串口蓝牙
    添加蓝牙通讯功能
    c# 注册表.代码示例.(迭代遍历注册表)[Demo]
    Vim Tips
    北京大学与苏州大学学生社会来源研究(1952年2002年) (zz)
    ES6的循环和可迭代对象
    JavaScript之this
    js数组去重的方法
  • 原文地址:https://www.cnblogs.com/mlllily/p/10280131.html
Copyright © 2020-2023  润新知