首页 > 编程语言 > 详细

Python基础-configparser和hashlib模块

时间:2017-10-19 14:29:25      阅读:176      评论:0      收藏:0      [点我收藏+]
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模块

原文:http://www.cnblogs.com/fansik/p/7692297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!