zoukankan      html  css  js  c++  java
  • 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
    猪猪侠要努力呀!
  • 相关阅读:
    px, pt, rpx, rem,
    tomcat报错LifecycleException的解决方案
    servlet系列
    tomcat startup.bat双击闪退解决方案。
    代码页
    editplus工具配置
    正则表达式常见字符集
    单片机TM4C123学习(六):看门狗
    stata学习笔记(七):回归分析和稳健性检验
    单片机TM4C123学习(五):UART的使用
  • 原文地址:https://www.cnblogs.com/mlllily/p/10280131.html
Copyright © 2011-2022 走看看