zoukankan      html  css  js  c++  java
  • 常用模块3

    一 logging模块

    import logging
    
    logging.basicConfig(
        # 1、日志输出位置:1、终端 2、文件
        filename='access.log', # 不指定,默认打印到终端
    
        # 2、日志格式
        format='%(asctime)s - %(name)s - %(levelname)s -%(module)s:  %(message)s',
    
        # 3、时间格式
        datefmt='%Y-%m-%d %H:%M:%S %p',
    
        # 4、日志级别
        # critical => 50
        # error => 40
        # warning => 30
        # info => 20
        # debug => 10
        level=10,
    )
    
    logging.debug('调试debug') # 10
    logging.info('消息info')   # 20
    logging.warning('警告warn')# 30
    logging.error('egon提现失败') # 40
    logging.critical('严重critical') # 50
    

    二 re模块

    import re
    
    print(re.findall('w','aAbc123_*()-='))
    print(re.findall('W','aAbc123_*()-= '))
    print(re.findall('s','aA
    bc	
    12f3_*()-= '))
    print(re.findall('S','aA
    bc	
    12f3_*()-= '))
    print(re.findall('d','aA
    bc	
    12f3_*()-= '))
    print(re.findall('D','aA
    bc	
    12f3_*()-= '))
    print(re.findall('D','aA
    bc	
    12f3_*()-= '))
    print(re.findall('Aalex',' alexis alex sb'))
                             alex
    print(re.findall('sb',' alexis alexsb sb'))
                                          sb
    print(re.findall('sb',"""alex
    alexis
    alex
    sb
    """))
    
    print(re.findall('^alex','alexis alex sb'))
    print(re.findall('sb$','alexis alex sb'))
    print(re.findall('sb$',"""alex
    alexis
    alex
    sb
    """))
    
    print(re.findall('^alex$','alexis alex sb'))
    print(re.findall('^alex$','al       ex'))
    print(re.findall('^alex$','alex'))
    
    重复匹配:| . | * | ? | .* | .*? | + | {n,m} |
    1、.:匹配除了
    之外任意一个字符,指定re.DOTALL之后才能匹配换行符
    print(re.findall('a.b','a1b a2b a b abbbb a
    b a	b a*b'))
                                                      a.b
    ['a1b','a2b','a b','abb','a	b','a*b']
    print(re.findall('a.b','a1b a2b a b abbbb a
    b a	b a*b',re.DOTALL))
    
    2、*:左侧字符重复0次或无穷次,性格贪婪
    print(re.findall('ab*','a ab abb abbbbbbbb bbbbbbbb'))
                                                   ab*
    ['a','ab','abb','abbbbbbbb']
    
    3、+:左侧字符重复1次或无穷次,性格贪婪
    print(re.findall('ab+','a ab abb abbbbbbbb bbbbbbbb'))
                            ab+
    
    4、?:左侧字符重复0次或1次,性格贪婪
    print(re.findall('ab?','a ab abb abbbbbbbb bbbbbbbb'))
                                                   ab?
    ['a','ab','ab','ab']
    
    5、{n,m}:左侧字符重复n次到m次,性格贪婪
    {0,} => *
    {1,} => +
    {0,1} => ?
    {n}单独一个n代表只出现n次,多一次不行少一次也不行
    
    print(re.findall('ab{2,5}','a ab abb abbb abbbb abbbbbbbb bbbbbbbb'))
                                                              ab{2,5}
    ['abb','abbb','abbbb','abbbbb]
    
    print(re.findall('d+.?d*',"asdfasdf123as1111111.123dfa12adsf1asdf3"))
                                                                      d+.?d*                                      d+.?d+
    
    
    []匹配指定字符一个
    print(re.findall('adb','a1111111b a3b a4b a9b aXb a b a
    b',re.DOTALL))
    print(re.findall('a[501234]b','a1111111b a3b a4b a9b aXb a b a
    b',re.DOTALL))
    print(re.findall('a[0-5]b','a1111111b a3b a1b a0b a4b a9b aXb a b a
    b',re.DOTALL))
    print(re.findall('a[0-9a-zA-Z]b','a1111111b axb a3b a1b a0b a4b a9b aXb a b a
    b',re.DOTALL))
    
    print(re.findall('a[^0-9a-zA-Z]b','a1111111b axb a3b a1b a0b a4b a9b aXb a b a
    b',re.DOTALL))
    print(re.findall('a-b','a-b aXb a b a
    b',re.DOTALL))
    print(re.findall('a[-0-9
    ]b','a-b a0b a1b a8b aXb a b a
    b',re.DOTALL))
    
  • 相关阅读:
    snmp
    iOS 精确定时器
    iOS 用命令实现简单的打包过程
    OpenSSH
    IOS 逆向工程之砸壳
    UNIX相关知识
    BSD历史
    linux grep命令
    为什么国外程序员爱用Mac?
    iOS xcuserdata
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/12616186.html
Copyright © 2011-2022 走看看