#配置文件
[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
[bitbucket.org]
User = hg
[topsecret.server.com]
Port = 50022
ForwardX11 = no
import configparser
#解析配置文件
conf = configparser.ConfigParser() #准备处理文件
# print(conf.sections())
conf.read('conf.ini')
print(conf.sections())
print(conf.default_section)
#取值
print(list(conf["bitbucket.org"]['User']))
for k,v in conf["bitbucket.org"].items():
print(k,v)
#判断参数
if 'sss' in conf["bitbucket.org"]:
print('in')
import configparser
conf = configparser.ConfigParser()
conf.read("conf_test.ini")
#查询
# print(dir(conf))
#
# print(conf.options("section1"))
#
# print(conf["section2"]['k1'])
#添加
# conf.add_section("section3")
#
# conf["section3"]["k"] = "v"
#
# conf["section3"]["k2"] = "v2"
#
# conf.write(open("conf_test_new.ini","w"))
#删除
conf.remove_option("section1","k2")
conf.write(open("conf_test2.ini","w"))
hashlib
import hashlib
m=hashlib.md5()
m.update(b'alex')
print(m.hexdigest())
print(len(m.hexdigest()))
print(len(m.hexdigest())*4)
print(hash("alex"))
传输结果
None
534b44a19bf18d20b71ecc4eb77c572f
32
128
-8103198363946390462
用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法
md5 讯息摘要的算法 ,可以产生出一个128位的散列值(hash),
md5特点:
1 压缩性:任意长度算出的md5值是固定的
2 容易计算: 从原数据计算出MD5值很容易
3 抗修改性
4 强抗碰撞
MD5用途
1 防止被篡改
2 防止直接看到明文
3 防止抵赖(数字签名)