zoukankan      html  css  js  c++  java
  • Python基础-configparser和hashlib模块

    configparser模块
    import configparser
    config = configparser.ConfigParser()
    #将配置写入到文件
    config['DEFAULT'] = {'ServerAliveInterval': '45',
                         'Compression': 'yes',
                         'CompressionLevel': '9'}
    config['bitbucket.org'] = {'User': 'fansik'}
    config['www.fansik.com'] = {'Host Port': '50022',
                                'ForwardX11': 'no'}
    config['DEFAULT']['ForwardX11'] = 'yes'
    
    with open('example.ini', 'w') as configfile:
        config.write(configfile)
    
    # 读取配置
    config.read('example.ini', encoding='utf8')
    print(config.sections())
    print(config.defaults())
    for key in config['bitbucket.org']: # 这个key包含DEFAULT中的内容
        print(key)
    
    # 修改配置
    config.remove_section('bitbucket.org')
    config.has_section('bitbucket.org') # 判断是否删除成功
    config.write(open('example.ini', 'w'))
    # 修改单个的配置
    config.set('www.fansik.com', 'forwardx11', 'yes')
    # 删除单个配置
    config.remove_option('www.fansik.com', 'forwardx11')

    hashlib加密模块

    import hashlib
    password = hashlib.md5()
    password.update('fanjinbao'.encode('utf8'))
    print(password)
    print(password.hexdigest())
    password.update('fansik'.encode('utf8'))
    print(password.hexdigest())
    
    password2 = hashlib.sha256()
    password2.update('fanjinbao'.encode('utf8'))
    print(password2.hexdigest())
    
    password3 = hashlib.sha256()
    password3.update('fanjinbao'.encode('utf8'))
    print(password2.hexdigest())
  • 相关阅读:
    Swift的函数与函数指针、闭包Closure等相关内容介绍
    spring+dubbo整合
    常用设计模式-适配器模式
    常用设计模式-工厂模式
    java动态代理
    程序对关系型数据库批量操作
    springboot整合mybatis
    JAVA代码实现多级树结构封装对象
    springboot集成redis缓存
    springboot入门
  • 原文地址:https://www.cnblogs.com/fansik/p/7692297.html
Copyright © 2011-2022 走看看