• day29


    # 面对对象三大特性
        #继承
            #单继承
            #多继承
        #多态:python天生支持,鸭子类型(list和tuple)
        #封装:私有的(__变量)
        # @property
        # @classmethod
        # @staticmethod
    # 面对对象进阶
        #issubclass isinstance
        #反射 hasattr getattr
        #内置方法:
            #__new__创建self构造方法
            #__call__ 对象()
    # 创建一个配置文档
    # import configparser
    #
    # config = configparser.ConfigParser()
    #
    # config["DEFAULT"] = {'ServerAliveInterval': '45',
    #                       'Compression': 'yes',
    #                      'CompressionLevel': '9',
    #                      'ForwardX11':'yes'
    #                      }
    #
    # config['bitbucket.org'] = {'User':'hg'}
    #
    # config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'}
    #
    # with open('example.ini', 'w') as configfile:
    #
    #    config.write(configfile)
    
    # import configparser
    # # config = configparser.ConfigParser()
    # # #---------------------------查找文件内容,基于字典的形式
    # # print(config.sections())        #  []
    # # config.read('example.ini')
    # # print(config.sections())        #   ['bitbucket.org', 'topsecret.server.com']
    # # print('bytebong.com' in config) # False
    # # print('bitbucket.org' in config) # True
    # # print(config['bitbucket.org']["user"])  # hg
    # # print(config['DEFAULT']['Compression']) #yes
    # # print(config['topsecret.server.com']['ForwardX11'])  #no
    # # print(config['bitbucket.org'])          #<Section: bitbucket.org>
    # # for key in config['bitbucket.org']:     # 注意,有default会默认default的键
    # #     print(key)
    # # print(config.options('bitbucket.org'))  # 同for循环,找到'bitbucket.org'下所有键
    # # print(config.items('bitbucket.org'))    #找到'bitbucket.org'下所有键值对
    # # print(config.get('bitbucket.org','compression')) # yes       get方法Section下的key对应的value
    # import configparser #增删改
    # config = configparser.ConfigParser()
    # config.read('example.ini')
    # config.add_section('yuan')
    # config.remove_section('bitbucket.org')
    # config.remove_option('topsecret.server.com',"forwardx11")
    # config.set('topsecret.server.com','k1','11111')
    # config.set('yuan','k2','22222')
    # config.write(open('new2.ini', "w"))
    
    # logging模块
    import logging
    # logging.debug('debug message')
    # logging.info('info message')
    # logging.warning('warning message')
    # logging.error('error message')
    # logging.critical('critical message')
    
    # import logging
    #
    # 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')
    #
    # logging.debug('debug message')
    # logging.info('info message')
    # logging.warning('warning message')
    # logging.error('error message')
    # logging.critical('critical message')
    
    import logging
    
    logger = logging.getLogger()
    # 创建一个handler,用于写入日志文件
    fh = logging.FileHandler('test.log',encoding='utf-8')
    
    # 再创建一个handler,用于输出到控制台
    ch = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    
    fh.setLevel(logging.DEBUG)
    
    fh.setFormatter(formatter)
    ch.setFormatter(formatter)
    logger.addHandler(fh) #logger对象可以添加多个fh和ch对象
    logger.addHandler(ch)
    
    logger.debug('logger debug message')
    logger.info('logger info message')
    logger.warning('logger warning message')
    logger.error('logger error message')
    logger.critical('logger critical message')
  • 相关阅读:
    5. Redis持久化
    4.Redis客户端
    3.Redis高级功能
    2.Redis五种数据结构
    1.Redis简介
    32.Mysql Cluster
    suffix ACM-ICPC 2017 Asia Qingdao
    多层BFS
    我想和你们说说java和C++___C加加
    11073 最热门的K个搜索串
  • 原文地址:https://www.cnblogs.com/wujunjie-sir/p/9285532.html
Copyright © 2020-2023  润新知