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())

  

原文地址:https://www.cnblogs.com/geeker-xjl/p/8900765.html