码迷,mamicode.com
首页 > 编程语言 > 详细

Python基础-configparser和hashlib模块

时间:2017-10-19 15:02:00      阅读:139      评论:0      收藏:0      [点我收藏+]

标签: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

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!