1.logging

  1. import logging
  2.  
  3. #-----------------------------------logging.basicConfig
  4. logging.basicConfig(
  5. level=logging.DEBUG,
  6. filename="logger.log",
  7. filemode="w",
  8. format="%(asctime)s %(filename)s[%(lineno)d] %(message)s"
  9.  
  10. )
  11. #
  12. # logging.debug('hello')
  13. # logging.info('hello')
  14. # logging.warning('warning message')
  15. # logging.error('error message')
  16. # logging.critical('critical message')
  17.  
  18. #-----------------------------------logger
  19. def logger():
  20. logger=logging.getLogger()
  21.  
  22. fh=logging.FileHandler("test_log")
  23. #ch=logging.StreamHandler()
  24.  
  25. fm=logging.Formatter("%(asctime)s %(message)s")
  26.  
  27. fh.setFormatter(fm)
  28. #ch.setFormatter(fm)
  29.  
  30. logger.addHandler(fh)
  31. #logger.addHandler(ch)
  32. logger.setLevel("DEBUG")
  33.  
  34. return logger
  35. # #----------------------
  36. logger=logger()
  37.  
  38. #
  39. # logger.debug("debug")
  40. # logger.info("info")
  41. # logger.warning("warning")
  42. # logger.error("error")
  43. # logger.critical("critical")
  44. #--------------------------------------------------
  45. import logging
  46. #
  47. logger=logging.getLogger()
  48.  
  49. logger1 = logging.getLogger('mylogger')
  50. logger1.setLevel(logging.DEBUG)
  51.  
  52. logger2 = logging.getLogger('mylogger')
  53. logger2.setLevel(logging.WARNING)
  54.  
  55. fh=logging.FileHandler("test_log-new")
  56. ch=logging.StreamHandler()
  57.  
  58. logger.addHandler(ch)
  59. logger.addHandler(fh)
  60.  
  61. logger1.addHandler(fh)
  62. logger1.addHandler(ch)
  63.  
  64. logger2.addHandler(fh)
  65. logger2.addHandler(ch)
  66.  
  67. # logger.debug('logger debug message')
  68. # logger.info('logger info message')
  69. # logger.warning('logger warning message')
  70. # logger.error('logger error message')
  71. # logger.critical('logger critical message')
  72.  
  73. # logger1.debug('logger1 debug message')
  74. # logger1.info('logger1 info message')
  75. # logger1.warning('logger1 warning message')
  76. # logger1.error('logger1 error message')
  77. # logger1.critical('logger1 critical message')
  78.  
  79. logger2.debug('logger2 debug message')
  80. logger2.info('logger2 info message')
  81. logger2.warning('logger2 warning message')
  82. logger2.error('logger2 error message')
  83. logger2.critical('logger2 critical message')

2.configparser

  1. import configparser
  2.  
  3. # config = configparser.ConfigParser() #config={}
  4. # #
  5. # #
  6. # #
  7. # #
  8. # config["DEFAULT"] = {'ServerAliveInterval': '45',
  9. # 'Compression': 'yes',
  10. # 'CompressionLevel': '9'}
  11. # #
  12. # #
  13. # #
  14. # config['bitbucket.org'] = {}
  15. # config['bitbucket.org']['User'] = 'hg'
  16. # #
  17. # config['topsecret.server.com'] = {}
  18. # topsecret = config['topsecret.server.com']
  19. # topsecret['Host Port'] = '50022' # mutates the parser
  20. # topsecret['ForwardX11'] = 'no' # same here
  21. # #
  22. # #
  23. # #
  24. # with open('example.ini', 'w') as f:
  25. # config.write(f)
  26.  
  27. #------------------------------------------------------增删改查、
  28. import configparser
  29. #
  30. config = configparser.ConfigParser()
  31.  
  32. #---------------------------------------------查
  33. # print(config.sections()) #[]
  34.  
  35. config.read('example.ini')
  36. # #
  37. # print(config.sections()) #['bitbucket.org', 'topsecret.server.com']
  38.  
  39. # print('bitbucket.org' in config)# False
  40. #
  41. # print(config['bitbucket.org']['User']) # hg
  42. #
  43. # print(config['DEFAULT']['Compression']) #yes
  44. #
  45. # print(config['topsecret.server.com']['ForwardX11']) #no
  46.  
  47. # for key in config['bitbucket.org']:
  48. # print(key)
  49.  
  50. #
  51. #
  52. # print(config.options('bitbucket.org'))#['user', 'serveraliveinterval', 'compression', 'compressionlevel', 'forwardx11']
  53. # print(config.items('bitbucket.org')) #[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9'), ('forwardx11', 'yes'), ('user', 'hg')]
  54. #
  55. # print(config.get('bitbucket.org','compression'))#yes
  56. #
  57. #
  58. # #---------------------------------------------删,改,增(config.write(open('i.cfg', "w")))
  59. #
  60. #
  61. config.add_section('yuan')
  62. config.set('yuan','k1','')
  63. #
  64. config.remove_section('topsecret.server.com')
  65. config.remove_option('bitbucket.org','user')
  66. # #
  67. #
  68. config.write(open('i.cfg', "w"))

3.md5加密

  1. # import hashlib
  2.  
  3. # obj=hashlib.md5()
  4. #
  5. # obj.update("admin".encode("utf8"))
  6. # print(obj.hexdigest()) #21232f297a57a5a743894a0e4a801fc3
  7.  
  8. # obj.update("adminroot".encode("utf8"))
  9. # print(obj.hexdigest())# 4b3626865dc6d5cfe1c60b855e68634a
  10. # 4b3626865dc6d5cfe1c60b855e68634a

day23-python之日志 re模块的更多相关文章

  1. python中日志logging模块的性能及多进程详解

    python中日志logging模块的性能及多进程详解 使用Python来写后台任务时,时常需要使用输出日志来记录程序运行的状态,并在发生错误时将错误的详细信息保存下来,以别调试和分析.Python的 ...

  2. [ Python入门教程 ] Python中日志记录模块logging使用实例

    python中的logging模块用于记录日志.用户可以根据程序实现需要自定义日志输出位置.日志级别以及日志格式. 将日志内容输出到屏幕 一个最简单的logging模块使用样例,直接打印显示日志内容到 ...

  3. python 的日志logging模块

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message')logging.info('This is info messag ...

  4. python的日志logging模块性能以及多进程

    写在前面: 日志是记录操作的一种好方式.但是日志,基本都是基于文件的,也就是要写到磁盘上的.这时候,磁盘将会成为一个性能瓶颈.对于普通的服务器硬盘(机械磁盘,非固态硬盘),python日志的性能瓶颈是 ...

  5. python 的日志logging模块学习

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...

  6. Python之日志 logging模块

    关于logging模块的日志功能 典型的日志记录的步骤是这样的: 创建logger 创建handler 定义formatter 给handler添加formatter 给logger添加handler ...

  7. Python中日志logging模块

    # coding:utf-8 import logging import os import time class Logger(object): def __init__(self): # 创建一个 ...

  8. python标准日志模块logging及日志系统设计

    最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下. python的标准库里的日志系统从Python2.3开始支持.只要import logging这个模块即可使用.如果你想开发 ...

  9. python标准日志模块logging的使用方法

    参考地址 最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下.python的标准库里的日志系统从Python2.3开始支持.只要import logging这个模块即可使用.如果 ...

  10. 【python】日志系统

    来源: http://blog.csdn.net/wykgf/article/details/11576721 http://www.jb51.net/article/42626.htm http:/ ...

随机推荐

  1. 利用Python进行数据分析 2017 第二版 项目代码

    最近在学习<利用Python进行数据分析>,找到了github项目的地址, 英文版本,中文版本 (非常感谢翻译中文的作者). mark一下,方便后边学习查找.

  2. 浅谈堆-Heap(一)

    应用场景和前置知识复习 堆排序 排序我们都很熟悉,如冒泡排序.选择排序.希尔排序.归并排序.快速排序等,其实堆也可以用来排序,严格来说这里所说的堆是一种数据结构,排序只是它的应用场景之一 Top N的 ...

  3. 开源的SSH框架优缺点分析

    开源是3个框架共有的优点 Struts2框架(MVC框架)的优点如下: 1) 实现了MVC模式,层次结构清晰,使程序员只需关注业务逻辑的实现: 2) 丰富的标签库,大大提高了开发的效率: 3) Str ...

  4. Quality of Service (QoS) in LTE

    Background: Why we need QoS ? There are premium subscribers who always want to have better user expe ...

  5. 前端专业术语: shim 和 Polyfill,了解下

    在学习和使用 JavaScript 的时候,我们会经常碰到两个术语:shim 和 polyfill.它们有许多定义和解释,意思相近又有差异. Shim Shim 指的是在一个旧的环境中模拟出一个新 A ...

  6. net 提供了Thread类用于线程的操作

    net 提供了Thread类用于线程的操作. 当初始化一个线程,把Thread.IsBackground=true的时候,指示该线程为后台线程.后台线程将会随着主线程的推出而退出.后台线程不妨碍程序的 ...

  7. SpringMVC06Exception 异常处理

    1.配置web.xml文件 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3// ...

  8. vue resource patch方法的传递数据 form data 为 [object Object]

    今天在测试 iblog 登录时,传送过去的数据总是 [object Object],以至于后台识别不出来. vue 使用了 vueResource 组件,登录方法为 patch. 经过探索,终于在官网 ...

  9. selenium+phantomjs报错:Unable to find a free port的分析和解决

    selenium+phantomjs报错:Unable to find a free port的分析和解决 Table of Contents 1. 现象 2. 分析 3. 解决办法 1 现象 在做项 ...

  10. windows 右键崩溃 解决方法

    [问题描述] 选中一个文件,右键之后无法弹出菜单,最后显示: 资源管理器未响应. [参考方法] https://www.jianshu.com/p/d627c941467a [方法介绍] 1.下载Sh ...