python—-模块知识拓展
标签:jsonaddges指示环境commhtmlreadline数值
1.hashlib ——configpraser——– xml
hashlib
模块导入:import hashlib
模块说明:用于将信息加密,明文变成密文
功能说明
MD5算法
m=hashlib.md5()将方法赋值给一个对象
m.update(\”hello world\”.encode(\”utf-8\”))#需要转换成字节类型
m.hexdigest()加密后的16进制的数据
SHA256算法
m=hashlib.sha256()
m.update(\”hello world\”.encode(\”utf-8\”))
m.hexdigest()#加密后的数据
注意:update的数据必须是字节类型
configparser
模块导入:import configparser 3.x improot ConfigParser 2.x
模块说明:用于生成配置文件 .ini文件
功能说明
生成配置文件
Python
import configparser
config = configparser.ConfigParser()#将方法写入一个对象中
config[\”DEFAULT\”] = {\”ipaddress\”:\”192.168.0.100\”,\”user\”:\”root\”,\”pasw\”:\”123\”,\”port\”:\”3306\”}
config[\”www.hairuinet.com\”] = {\”name\”:\”hairui\”,\”index\”:\”www.hairuinet.com\”}
config[\”www.92hairui.cn\”] ={\”name\”:\”hairui\”,\”index\”:\”www.92hairui.com\”}#创建里面section
with open(\”web.ini\”,\”w\”) as f:#写入文件
config.write(f