zoukankan      html  css  js  c++  java
  • Pyhton学习——Day23

    #re模块方法:findall search
    #findall:返回所有满足匹配条件的数值,放在列表里
    #search : #函数会在字符串内查找模式匹配,只到找到第一个匹配然后返回一个包含匹配信息的对象,该对象可以
    # 通过调用group()方法得到匹配的字符串,如果字符串没有匹配,则返回None。
    #match : 同search,不过仅在字符串开始出进行匹配
    import re
    # res = re.match('d+','alex36wusir24')
    # print(res)
    # res = re.split('[ |]','hello abc|def')
    # print(res)
    # sub()用于替换匹配的字符串
    # res = re.sub('d','A','asdasdas1564agasd15a5sd4',4)
    # print(res)
    # compile替换指定的方法,自定义规则,可以使用多次
    # finditer findall是放在列表,finditer返回的是一个迭代器对象,当处理数据非常大时,可以使用该命令处理
    # res = re.findall('www.(baidu|163).com','www.baidu.com')
    # print(res)
    #当findall匹配包含分组的过程,会优先打印匹配分组的内容
    # F:PythonPythonLeaningvenvScriptspython.exe F:/Python/PythonLeaning/每日学习打卡/Day23.py
    # ['baidu']
    #
    # Process finished with exit code 0
    ############################################################################################################
    # 正则表达式总结:
    # 重点在字符集[]和转移字符
    # res = re.search('abc|bcd','bcd')
    # print(res)
    #search只能匹配到第一个
    ############################################################################################################
    ############################################################################################################
    ############################################################################################################
    ############################################################################################################
    ############################################################################################################
    ############################################################################################################
    # logging模块:日志文件,提供了一个借口,调用方法完成对日志文件的操作
    import logging
    # logging.basicConfig( 文件的基本功能
    # level=logging.DEBUG, 调整默认级别
    # filename = 'logger.log' , 存至某一个文件
    # filemode = 'w' , 只写文件
    # format = '%(asctime)s' 设定日期格式
    #
    # )
    # logging.debug('debug msg') debug、info、warning、error、critical日志级别,逐级升高,显示的内容需要通过级别来控制
    # logging.info('info msg') 默认级别warning,比warning级别高的才能打印,可以调整参数
    # logging.warning('warning msg')
    # logging.error('error msg')
    # logging.critical('critical msg')
    # #_____________________________________________________________________________________________#
    # F:PythonPythonLeaningvenvScriptspython.exe F:/Python/PythonLeaning/每日学习打卡/Day23.py
    # WARNING:root:warning msg
    # ERROR:root:error msg
    # CRITICAL:root:critical msg
    # Process finished with exit code 0

    # 可见,默认情况下Python的logging模块将日志打印到了标准输出中,且只显示了大于等于WARNING级别的日志,
    # 这说明默认的日志级别设置为WARNING(日志级别等级CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET),
    # 默认的日志格式为日志级别:Logger名称:用户输出消息。
    # format参数中可能用到的格式化串:
    # %(name)s Logger的名字
    # [重要]%(levelno)s 数字形式的日志级别
    # [重要]%(levelname)s 文本形式的日志级别
    # %(pathname)s 调用日志输出函数的模块的完整路径名,可能没有
    # %(filename)s 调用日志输出函数的模块的文件名
    # %(module)s 调用日志输出函数的模块名
    # %(funcName)s 调用日志输出函数的函数名
    # %(lineno)d 调用日志输出函数的语句所在的代码行
    # %(created)f 当前时间,用UNIX标准的表示时间的浮 点数表示
    # %(relativeCreated)d 输出日志信息时的,自Logger创建以 来的毫秒数
    # [重要]%(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒
    # %(thread)d 线程ID。可能没有
    # %(threadName)s 线程名。可能没有
    # %(process)d 进程ID。可能没有
    # [重要]%(message)s用户输出的消息
    #################################################################################################################
    #logger对象 屏幕上显示,文件里也输入
    # logger = logging.getLogger()
    # fh = logging.FileHandler('test.log') #可以向文件里发送日志
    # ch = logging.StreamHandler() #可以向屏幕里发送日志
    # fm = logging.Formatter('%(asctime)s %(message)s')
    # fh.setFormatter(fm)
    # ch.setFormatter(fm)
    # logger.addHandler(fh)
    # logger.addHandler(ch)
    # #logger具备同时发文件和屏幕信息
    # logger.debug('hello')
    # logger.info('asd')
    # logger.warning('yes')
    # logger.error('error')
    # logger.critical('critical')
    ###############################################################################################################
    # F:PythonPythonLeaningvenvScriptspython.exe F:/Python/PythonLeaning/每日学习打卡/Day23.py
    # 2018-02-26 10:57:32,644 yes
    # 2018-02-26 10:57:32,645 error
    # 2018-02-26 10:57:32,645 critical
    # Process finished with exit code 0
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    # configparser模块:主要用于操作配置文件,相当于操作一个大的字典文件
    # 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)
    #——————————————————————————————————————————————————————#
    #文件的增删改查
    # import configparser
    # config = configparser.ConfigParser()
    # config.read('example.ini')
    # print(config.sections()) #['bitbucket.org', 'topsecret.server.com']
    # print(config['DEFAULT']['Compression'])#yes
    # for key in config['bitbucket.org']:
    # print(key)
    #查——————————————————————————————————————————
    #[DEFAULT]会随任意键打印而打印,是属于特殊的关键信息
    # items是将键和值组成字典去取值
    # get 是连续取值
    #删、改、增——————————————————————————————————————
    # config.write(open('i.cfg','w')) 一定要写
    # config.add_section('yuan')#对文件增加一个块
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    ###############################################################################################################
    import hashlib
    #用于加密的操作,MD5算法只能把明文变成密文,加密后位数是固定的
    obj = hashlib.md5()
    obj.update("hello".encode('utf-8'))
    print(obj.hexdigest())











    Win a contest, win a challenge
  • 相关阅读:
    蓝桥网试题 java 基础练习 特殊的数字
    蓝桥网试题 java 基础练习 杨辉三角形
    蓝桥网试题 java 基础练习 查找整数
    蓝桥网试题 java 基础练习 数列特征
    蓝桥网试题 java 基础练习 字母图形
    蓝桥网试题 java 基础练习 01字串
    蓝桥网试题 java 基础练习 回文数
    蓝桥网试题 java 基础练习 特殊回文数
    Using text search in Web page with Sikuli
    each of which 用法
  • 原文地址:https://www.cnblogs.com/pandaboy1123/p/8476906.html
Copyright © 2011-2022 走看看