标签:eve server port ini bucket imp def war res
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())
Python基础-configparser和hashlib模块
标签:eve server port ini bucket imp def war res
原文地址:http://www.cnblogs.com/fansik/p/7692297.html