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())
  • 相关阅读:
    debian7安装oracle11g
    unix fopen和fopen_s用法的比较
    QT的三种协议说明
    Qt之遍历文件夹
    Debian 7 安装配置总结
    用户不在sudoers文件中的解决方法 .
    QT断点续传
    QFtp类参考
    FTP服务器简易有效的访问方法
    Java爬虫搜索原理实现
  • 原文地址:https://www.cnblogs.com/fansik/p/7692297.html
Copyright © 2011-2022 走看看