configparse模块和hashlib模块
Posted 红桃6
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了configparse模块和hashlib模块相关的知识,希望对你有一定的参考价值。
# import configparser # # config = configparser.ConfigParser() #config = {} # config[‘DEFAULT‘] = {‘ServerAliveInterval‘:‘45‘, # ‘Compression‘:‘yes‘, # ‘CompressionLevel‘:‘9‘} # # config[‘bitbucket.org‘] = {} # config[‘bitbucket.org‘][‘User‘] = ‘hg‘ # # config[‘topsecret.server.com‘] = {} # topsecret = config[‘topsecret.server.com‘] # topsecret[‘Host Port‘] = ‘50022‘ # topsecret[‘ForwardX11‘] = ‘no‘ # config[‘DEFAULT‘][‘ForwardX11‘] = ‘yes‘ # # # with open(‘example.ini‘,‘w‘) as f: # config.write(f) import configparser config = configparser.ConfigParser() #config = {} config.read(‘example.ini‘) # 查 # print(config.sections()) # print(‘bytehong.com‘ in config) # print(config[‘bitbucket.org‘][‘User‘]) # print(config[‘DEFAULT‘][‘Compression‘]) # print(config[‘topsecret.server.com‘][‘ForwardX11‘]) # for key in config[‘bitbucket.org‘]: # print(key) # print(config.options(‘bitbucket.org‘)) # print(config.items(‘bitbucket.org‘)) # print(config.get(‘bitbucket.org‘,‘compression‘)) # 增 # config.add_section(‘hello‘) # config.set(‘hello‘,‘k1‘,‘123‘) # 删 # config.remove_section(‘topsecret.server.com‘) # config.remove_option(‘bitbucket.org‘,‘User‘) config.write(open(‘test.txt‘,‘w‘))
# 用于加密相关的操作,主要提sha1,sha224,sha384,sha512,md5算法 # 算法越复杂,消耗的时间越多 import hashlib # obj = hashlib.md5(‘sb‘.encode(‘utf-8‘)) obj = hashlib.md5() # obj.update("hello".encode(‘utf-8‘)) # print(obj.hexdigest()) # obj.update(‘helloroot‘.encode(‘utf-8‘)) # print(obj.hexdigest())
以上是关于configparse模块和hashlib模块的主要内容,如果未能解决你的问题,请参考以下文章
python封装configparser模块获取conf.ini值(优化版)