zoukankan      html  css  js  c++  java
  • PythonDay5

    ConfigParser模块

    configparser模块主要是用来生成和修改配置文件

    比如要生成一个example1.ini的配置文件可以如下:

     1 import configparser
     2 
     3 config = configparser.ConfigParser()
     4 config["DEFAULT"]= {'ServerAliveInterval':'45',
     5                     'Compression':'yes',
     6                     'CoompressiinLevel':'9'}
     7 config['bitbucket.org'] = {}
     8 config['bitbucket.org']['User'] = 'hg'
     9 
    10 config['topsevret.server.com'] = {}
    11 topsectret = config['topsevret.server.com'] #这里只不过是更换了一个变量来赋值
    12 topsectret['Host Port'] = '4001'
    13 topsectret['Forwardx11'] = "no"
    14 config['DEFAULT']['ForwardX11'] = 'yes'
    15 
    16 config["mypython.com"] = {'name':'peng',
    17                             'age':'25',
    18                             'job':'IT'}
    19 config["mypython.com"]['job'] = 'AI'
    20 
    21 with open("example1.ini",'w') as configfile:
    22     config.write(configfile)
    View Code

    但大部分时间配置文件都是用手动修改,然后我们的工程代码里面是读出来的,例如:

    1 import configparser
    2 
    3 conf = configparser.ConfigParser()
    4 conf.read("example1.ini")
    5 
    6 print(conf.defaults())
    7 print(conf.sections())
    8 print(conf['mypython.com']['age'])
    View Code

     那么读出来的结果如下:

    Hashlib模块

    Hashlib模块包括MD5和SHA, 包括了SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法,一般来说SHA比MD5算法更好,且SHA512比SHA1、SHA224等更优秀;

    另外,MD5算法是反解不了,有些可以得出明文,实际是撞库等方式得到的。

     1 #md5其实是不能反解的,有的能输出明文是用撞库等方式得到的
     2 import  hashlib
     3 
     4 m = hashlib.md5()
     5 m2 = hashlib.md5()
     6 m.update(b"peng")  #1b77697b886efcf3fe95a8839064c1cb
     7 print(m.hexdigest())
     8 m.update(b"junfei") #其实这里生成的MD5是pengjunfei的加在一起的计算结果 f2e1ce014a4fdab21b2fb78d782e3de5
     9 print(m.hexdigest())
    10 
    11 m2.update(b"pengjunfei") #f2e1ce014a4fdab21b2fb78d782e3de5
    12 print(m2.hexdigest())
    View Code

    hmac模块

    消息加密中使用,但实际使用过程,得发送和接收的双方知道key。这个加密模块的加密方式比较快。

    1 import  hmac
    2 
    3 h_test = hmac.new("PengDeTesila".encode(encoding="utf-8"))
    4 print(h_test.digest())
    5 print(h_test.hexdigest())
    View Code
  • 相关阅读:
    Visual C++ 打印编程技术-内存设备环境
    MySQL存储引擎
    记录阿里云服务器docker安装wordpress
    记录dockerfile参数
    记录一次 在公网使用FRP内网穿透开源软件,通过SSH连接内网服务器
    记录一次docker安装zabbix5.0
    记录一次zabbix邮件告警搭建过程和问题处理
    记录一次yum-config-manager命令的使用
    记录一次解决zabbix5.0图形化界面文字乱码的问题
    记录一次查看本地端口10050被哪个IP地址访问
  • 原文地址:https://www.cnblogs.com/xiaofei1106/p/10499306.html
Copyright © 2011-2022 走看看